Powered By Blogger

Friday 6 May 2011

cs304 solution # 2

//header files
#include<iostream.h>
#include<conio.h>

// state class defination
class state
//hidden part
{ private :
char name[10];
int num_of_cities;
int population;
//interface
public
state(){}
void setname(char.name1)
{
for(int i=0;i<10;i++ )
name[i]=name1[i];
}
void setnumber(int num1)
{
num_of_cities=num1;
}
void setpop(int pop1)
{
population=pop1;
}
char* getname()
{
return name;
}
int getpop()
{
return population;
}
void input()
{
char name[10];
int num, pop;
cout<>nme;
setname(nme);
cout<>num;
setnumber(num);
cout<>pop;
setpop(pop);
}
~state(){}
};
//country class definition
class country
{
// hidden part
private:
//state type array
state ss[3];
long country_pop;
//interface
public:
country()
{country_pop=0;}
//calculation counrtry population
void cal_country_pop()
{
for(int i=0;i<3;i++)
{
cout<<"enter data about"<<"state"<<i+1<<"\n\n";
ss[i].input();
country_pop=country_pop+ss[i].getpop();
}
}
//display output
void diplay()
{
for (int i=0;i<3;i++)
{
cout<<"\nstate name\t"<<ss[i].getname();
cout<<"\nstate population\t"<<ss[i].getpop();
}
cout<<"\n\n\ntotal population of country is\t"<<country_pop;
}
~country(){}
};
main(){
//declaring country object
country abc;
//calling cal_country_pop
abc.call_country_pop();
//calling display
abc.display();
getch();
}







1 comment: