본문내용
;
public:
Americano() : Coffee()
{
cout<<"아메리카노입니다."<
}
};
int main()
{
Americano u1;
Cappuccino u2;
Latte u3;
Mocha u4;
return 0;
}
6. 2차원 도형들을 나타내는 클래스들을 작성하여 보자.
#include
#include
using namespace std;
class Shape {
private:
double startx;
double starty;
double area;
double height;
double width;
public:
Shape(double x, double y, double h, double w)
{
startx = x;
starty = y;
height = h;
width = w;
}
void setStartx(double x)
{
startx = x;
}
void setStarty(double y)
{
starty = y;
}
void setArea(double a)
{
area = a;
}
void setHeight(double h)
{
height = h;
}
void setWidth(double w)
{
width = w;
}
double getStartx()
{
return startx;
}
double getStarty()
{
return starty;
}
double getArea()
{
return area;
}
double getHeight()
{
return height;
}
double getWidth()
{
return width;
}
};
class Rectangle : public Shape{
private:
public:
Rectangle(double x, double y, double h, double w) : Shape(x,y,h,w)
{
}
int getArea()
{
return getWidth()*getHeight();
}
};
class Triangle : public Shape{
private:
public:
Triangle(double x, double y, double h, double w) : Shape(x,y,h,w)
{
}
int getArea()
{
return getWidth()*getHeight()/2;
}
};
int main()
{
Rectangle r(3,4,5,2);
Triangle t(4,5,2,5);
cout<<"Rectangle 의 면적 : "<
cout<<"Triangle 의 면적 : "<
return 0;
}
7. 다음 그림에 해당하는 클래스를 작성하여 보자.
#include
#include
using namespace std;
class Student {
private:
string name;
string snum;
string major;
int grade;
int credit;
public:
Student(string n, string sn, string m, int g, int c)
{
name = n;
snum = sn;
major = m;
grade = g;
credit = c;
}
void setName(string n)
{
name = n;
}
void setSnum(string sn)
{
snum = sn;
}
void setMajor(string m)
{
major = m;
}
void setGrade(int g)
{
grade = g;
}
void setCredit(int c)
{
credit = c;
}
string getName()
{
return name;
}
string getSnum()
{
return snum;
}
string getMajor()
{
return major;
}
int getGrade()
{
return grade;
}
int getCredit()
{
return credit;
}
void print()
{
cout<<"이 름 : "<
cout<<"학 번 : "<
cout<<"소속학과 : "<
cout<<"학 년 : "<
cout<<"이수학점 : "<
}
};
class UnderGraduate : public Student{
private:
string club;
public:
UnderGraduate(string n, string sn, string m, int g, int c, string club) : Student( n, sn, m, g, c)
{
this->club = club;
}
void setClub(string c)
{
club = c;
}
string getClub()
{
return club;
}
void print()
{
Student::print();
cout<<"동아리명 : "<
}
};
class Graduate : public Student{
private:
string assistant;
double srate;
public:
Graduate(string n, string sn, string m, int g, int c, string as, double sr) : Student( n, sn, m, g, c)
{
assistant = as;
srate = sr;
}
void print()
{
Student::print();
cout<<"조교유형 : "<
cout<<"장학비율 : "<
}
};
int main()
{
Graduate g("홍길동","20051111","컴퓨터공학과",4, 140,"연구조교", 0.5);
UnderGraduate u("하길동","20011111","컴퓨터공학과",2, 80,"Visaul C++");
g.print();
cout<<"-------------------------"<
u.print();
return 0;
}
public:
Americano() : Coffee()
{
cout<<"아메리카노입니다."<
};
int main()
{
Americano u1;
Cappuccino u2;
Latte u3;
Mocha u4;
return 0;
}
6. 2차원 도형들을 나타내는 클래스들을 작성하여 보자.
#include
#include
using namespace std;
class Shape {
private:
double startx;
double starty;
double area;
double height;
double width;
public:
Shape(double x, double y, double h, double w)
{
startx = x;
starty = y;
height = h;
width = w;
}
void setStartx(double x)
{
startx = x;
}
void setStarty(double y)
{
starty = y;
}
void setArea(double a)
{
area = a;
}
void setHeight(double h)
{
height = h;
}
void setWidth(double w)
{
width = w;
}
double getStartx()
{
return startx;
}
double getStarty()
{
return starty;
}
double getArea()
{
return area;
}
double getHeight()
{
return height;
}
double getWidth()
{
return width;
}
};
class Rectangle : public Shape{
private:
public:
Rectangle(double x, double y, double h, double w) : Shape(x,y,h,w)
{
}
int getArea()
{
return getWidth()*getHeight();
}
};
class Triangle : public Shape{
private:
public:
Triangle(double x, double y, double h, double w) : Shape(x,y,h,w)
{
}
int getArea()
{
return getWidth()*getHeight()/2;
}
};
int main()
{
Rectangle r(3,4,5,2);
Triangle t(4,5,2,5);
cout<<"Rectangle 의 면적 : "<
}
7. 다음 그림에 해당하는 클래스를 작성하여 보자.
#include
#include
using namespace std;
class Student {
private:
string name;
string snum;
string major;
int grade;
int credit;
public:
Student(string n, string sn, string m, int g, int c)
{
name = n;
snum = sn;
major = m;
grade = g;
credit = c;
}
void setName(string n)
{
name = n;
}
void setSnum(string sn)
{
snum = sn;
}
void setMajor(string m)
{
major = m;
}
void setGrade(int g)
{
grade = g;
}
void setCredit(int c)
{
credit = c;
}
string getName()
{
return name;
}
string getSnum()
{
return snum;
}
string getMajor()
{
return major;
}
int getGrade()
{
return grade;
}
int getCredit()
{
return credit;
}
void print()
{
cout<<"이 름 : "<
};
class UnderGraduate : public Student{
private:
string club;
public:
UnderGraduate(string n, string sn, string m, int g, int c, string club) : Student( n, sn, m, g, c)
{
this->club = club;
}
void setClub(string c)
{
club = c;
}
string getClub()
{
return club;
}
void print()
{
Student::print();
cout<<"동아리명 : "<
};
class Graduate : public Student{
private:
string assistant;
double srate;
public:
Graduate(string n, string sn, string m, int g, int c, string as, double sr) : Student( n, sn, m, g, c)
{
assistant = as;
srate = sr;
}
void print()
{
Student::print();
cout<<"조교유형 : "<
};
int main()
{
Graduate g("홍길동","20051111","컴퓨터공학과",4, 140,"연구조교", 0.5);
UnderGraduate u("하길동","20011111","컴퓨터공학과",2, 80,"Visaul C++");
g.print();
cout<<"-------------------------"<
return 0;
}
소개글