본문내용
나타내는 클래스 Nation을 작성하여 보자.
Nation클래스를 정의하고 적절한 생성자를 추가하라.
접근자와 생성자를 비롯하여 필요한 멤버 함수들을 추가하라.
main()에서 몇 개의 Nation객체를 생성하고 가장 인구가 많은 국가, 가장 국민 소득이 높은 국가를 탐색하여 화면에 출력하는 프로그램을 작성하라.
#include
#include
using namespace std;
class Nation{
private:
string country;
double population;
double area;
double income;
public:
Nation(){}
Nation(string c, double p, double a, double i)
{
country = c;
population = p;
area = a;
income = i;
}
void setCountry(string c)
{
country = c;
}
void setPopulation(double p)
{
population = p;
}
void setArea(double a)
{
area = a;
}
void setIncome(double i)
{
income = i;
}
string getCountry()
{
return country;
}
double getPopulation()
{
return population;
}
double getArea()
{
return area;
}
double getIncome()
{
return income;
}
void print()
{
cout<<"국가 이름 : "<
cout<<"인 구 : "<
cout<<"넓 이 : "<
cout<<"국민 소득 : "<
}
};
int main()
{
double p1,p2,p3;
Nation n1("대한민국",4977,100032,17074), n2("일본",12728,377835,39731), n3;
n3.setCountry("중국");
n3.setPopulation(133004);
n3.setArea(9596960);
n3.setIncome(3677);
cout<<"========================================"<
n1.print();
n2.print();
n3.print();
cout<<"========================================"<
cout<<"가장 인구가 많은 국가"<
if(n1.getPopulation() < n2.getPopulation()){
if(n2.getPopulation() > n3.getPopulation()){
n2.print();
}
else{
n3.print();
}
}
else{
if(n1.getPopulation() > n3.getPopulation()){
n1.print();
}
else{
n3.print();
}
}
cout<<"========================================"<
cout<<"가장 국민소득이 높은 국가"<
if(n1.getIncome() < n2.getIncome()){
if(n2.getIncome() > n3.getIncome()){
n2.print();
}
else{
n3.print();
}
}
else{
if(n1.getIncome() > n3.getIncome()){
n1.print();
}
else{
n3.print();
}
}
return 0;
}
5. 핸드폰의 문자 메시지를 나타내는 클래스 SMS를 작성하여 보자.
적절한 생성자를 추가하라.
멤버 함수 setText()는 문자 메시지의 텍스트를 설정한다. 멤버 함수 print()는 메시지에 헤더를 붙여서 콘솔에 출력한다.
몇 개의 문자 메시지를 생성하여서 테스트하라.
#include
#include
using namespace std;
class SMS{
private:
string transnum;
string receptionnum;
string msgtext;
string time;
public:
SMS(){}
SMS(string tnum, string rnum)
{
transnum = tnum;
receptionnum = rnum;
}
SMS(string tnum, string rnum, string m, string t)
{
transnum = tnum;
receptionnum = rnum;
msgtext = m;
time = t;
}
void setTransnum(string tnum)
{
transnum = tnum;
}
void setReceptionnum(string rnum)
{
receptionnum = rnum;
}
void setMsgtext(string m)
{
msgtext = m;
}
void setTime(string t)
{
time = t;
}
string getTransnum()
{
return transnum;
}
string getReceptionnum()
{
return receptionnum;
}
string getMsgtext()
{
return msgtext;
}
string getTime()
{
return time;
}
void print()
{
cout<<"송신자 : "<
cout<<"시 각 : "<
cout<<"메시지 : "<
}
};
int main()
{
SMS m1("010-555-2111","010-555-1111","Hi","03:10"), m2("010-555-1111","010-555-2111");
m2.setTime("03:11");
m2.setMsgtext("Hm..");
m1.print();
cout<<"============================"<
m2.print();
return 0;
}
Nation클래스를 정의하고 적절한 생성자를 추가하라.
접근자와 생성자를 비롯하여 필요한 멤버 함수들을 추가하라.
main()에서 몇 개의 Nation객체를 생성하고 가장 인구가 많은 국가, 가장 국민 소득이 높은 국가를 탐색하여 화면에 출력하는 프로그램을 작성하라.
#include
#include
using namespace std;
class Nation{
private:
string country;
double population;
double area;
double income;
public:
Nation(){}
Nation(string c, double p, double a, double i)
{
country = c;
population = p;
area = a;
income = i;
}
void setCountry(string c)
{
country = c;
}
void setPopulation(double p)
{
population = p;
}
void setArea(double a)
{
area = a;
}
void setIncome(double i)
{
income = i;
}
string getCountry()
{
return country;
}
double getPopulation()
{
return population;
}
double getArea()
{
return area;
}
double getIncome()
{
return income;
}
void print()
{
cout<<"국가 이름 : "<
};
int main()
{
double p1,p2,p3;
Nation n1("대한민국",4977,100032,17074), n2("일본",12728,377835,39731), n3;
n3.setCountry("중국");
n3.setPopulation(133004);
n3.setArea(9596960);
n3.setIncome(3677);
cout<<"========================================"<
n2.print();
n3.print();
cout<<"========================================"<
if(n2.getPopulation() > n3.getPopulation()){
n2.print();
}
else{
n3.print();
}
}
else{
if(n1.getPopulation() > n3.getPopulation()){
n1.print();
}
else{
n3.print();
}
}
cout<<"========================================"<
if(n2.getIncome() > n3.getIncome()){
n2.print();
}
else{
n3.print();
}
}
else{
if(n1.getIncome() > n3.getIncome()){
n1.print();
}
else{
n3.print();
}
}
return 0;
}
5. 핸드폰의 문자 메시지를 나타내는 클래스 SMS를 작성하여 보자.
적절한 생성자를 추가하라.
멤버 함수 setText()는 문자 메시지의 텍스트를 설정한다. 멤버 함수 print()는 메시지에 헤더를 붙여서 콘솔에 출력한다.
몇 개의 문자 메시지를 생성하여서 테스트하라.
#include
#include
using namespace std;
class SMS{
private:
string transnum;
string receptionnum;
string msgtext;
string time;
public:
SMS(){}
SMS(string tnum, string rnum)
{
transnum = tnum;
receptionnum = rnum;
}
SMS(string tnum, string rnum, string m, string t)
{
transnum = tnum;
receptionnum = rnum;
msgtext = m;
time = t;
}
void setTransnum(string tnum)
{
transnum = tnum;
}
void setReceptionnum(string rnum)
{
receptionnum = rnum;
}
void setMsgtext(string m)
{
msgtext = m;
}
void setTime(string t)
{
time = t;
}
string getTransnum()
{
return transnum;
}
string getReceptionnum()
{
return receptionnum;
}
string getMsgtext()
{
return msgtext;
}
string getTime()
{
return time;
}
void print()
{
cout<<"송신자 : "<
};
int main()
{
SMS m1("010-555-2111","010-555-1111","Hi","03:10"), m2("010-555-1111","010-555-2111");
m2.setTime("03:11");
m2.setMsgtext("Hm..");
m1.print();
cout<<"============================"<
return 0;
}
소개글