#include <iostream> #include <cstring> #include <string> using namespace std; class Dog { private: char dog_Name[30]; char breed[30]; int age; static int lic_fee; public: Dog(); void setListData(char*pn,char*on,int a); void displayDog(); void displayInfo(); }; Dog::Dog() { strcpy(dog_Name,""); strcpy(breed,""); age=0; static double lic_fee = 12.25; } void Dog::setListData(char*pN,char*on,int a) { strcpy(dog_Name,pN); strcpy(breed,on); age=a; static double lic_fee = 12.25; } void Dog::displayDog() { cout <<"Dog Name: "<< dog_Name << "Dog Breed: " << breed << "Age of Dog: " << age << "License Fee: " << lic_fee << endl; } void DisplayInfo(Dog DogRec[], int p = 8) { cout << "Dog Name \t Breed \t Dog Age \t License Fee" << endl; for(int i=0;i<p; ++i) { if(strcmp(DogRec[i]) == 0) { cout << DogRec[i].dog_Name << '\t'<< breed[i]<< '\t' << age[i]<< '\t' << lic_fee<< endl; } } } #include <iostream> #include <string> #include <cstring> #include "dog.h" using namespace std; void main() { Dog DogRec[8]; DogRec[0].setListData("Rocko", "Maltese", 4); DogRec[1].setListData("Nicki", "Terrier", 9); DogRec[2].setListData("Harvey", "Golden Retriever", 15); DogRec[3].setListData("Dale Jr", "Boxer", 38); DogRec[4].setListData("Boxer", "Boxer", 8); DogRec[5].setListData ("JJ", "German Sheperd", 5); DogRec[6].setListData("Misty", "Collie", 46); DogRec[7].setListData("Carter", "Cocker Spaniel”, 7); DisplayInfo(DogRec,8); getch(); }
Selasa, 10 April 2012
Program Class C++
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar