문제1. 자신의 학과, 학번, 이름을 출력하는 프로그램을 작성하세요.
조건 1. ‘추가부분’에 소스코드를 추가.
결과물

소스
/*
만든이 : NoSyu
만든 날짜 : 2008-09-23
프로그램 설명
문제1. 자신의 학과, 학번, 이름을 출력하는 프로그램을 작성하세요.
조건 1. ‘추가부분’에 소스코드를 추가.
*/
#include <iostream> // iostream include
// using standard input/ouput
using std::cout;
using std::cin;
using std::endl;
// function declaration
// class declaration
class Student
{
private:
char studentName[20];
char studentMajor[30];
int studentID;
public:
/*
setdata function
return : void
argument
name : student name.
mojor : student mojor.
id : sutdent id number.
set the class member variable
*/
void setdata(char* name, char* major, int id)
{
strcpy(studentName, name);
strcpy(studentMajor, major);
studentID = id;
}
/*
printme function
return : void
argument : void
print the class member variable
*/
void printme(void)
{
cout << "Name : " << studentName << endl;
cout << "Major : " << studentMajor << endl;
cout << "StudentID : " << studentID << endl;
}
};
// main function
int main(void)
{
Student BJY; // BJY is student
BJY.setdata("박진영", "컴퓨터공학과", 2004314081); // set data to class BJY
BJY.printme(); // print the student information.
return 0; // 종료~
}
문제2. 클래스를 사용하여 삼각형, 사각형, 원의 넓이를 구하는 프로그램 작성하세요.
조건 1. ‘추가부분’에 소스코드 추가.
조건 2. SetValue와 Circle는 내부 정의 함수.
조건 3. Triangle과 Square는 외부 정의 함수.
조건 4. 사용자로부터 height와 weight값을 받아 올 수 있도록 구현.
결과물

소스
/*
만든이 : NoSyu
만든 날짜 : 2008-09-23
프로그램 설명
문제1. 자신의 학과, 학번, 이름을 출력하는 프로그램을 작성하세요.
*/
#include <iostream> // iostream include
// using standard input/ouput
using std::cout;
using std::cin;
using std::endl;
// function declaration
// class declaration
class Dimension
{
private:
double height;
double weight;
public:
void SetValue() // height와 weight값 설정
{
// print the message
cout << "Insert Value" << endl;
// get the weight data
cout << "Weight = ";
cin >> weight;
// get the height data
cout << "Height = ";
cin >> height;
}
double Circle() // 원 넓이
{
// circle area = pi * (1/2 * height)^2
const double PI = 3.14;
return ((PI * height * height) / 4);
}
double Triangle(); // 삼각형 넓이
double Square(); // 사각형 넓이
};
// class function definition
double Dimension::Triangle()
{
// triangle area = 1/2 * weight * height
return (weight * height / 2);
}
double Dimension::Square()
{
// square area = weight * height
return (weight * height);
}
// main function
int main(void)
{
Dimension D2; // 2D class
D2.SetValue(); // set value from user
// print the Result Value
cout << "----------------------------" << endl;
cout << "Result value" << endl;
cout << "Circle = " << D2.Circle() << endl;
cout << "Triangle = " << D2.Triangle() << endl;
cout << "Square = " << D2.Square() << endl;
return 0; // 종료~
}
- 2008년 2학기 인간컴퓨터상호작용 - 4th Homework (0)2008/10/26
- 2008년 2학기 자료구조 - mmult code (18)2008/10/20
- 2008년 2학기 인간컴퓨터상호작용 - 3rd Homework (0)2008/10/08
- 2008년 2학기 컴퓨터공학실습2 - Report 02 (0)2008/10/05
- 2008년 2학기 인간컴퓨터상호작용 - UbiComp 2008 (0)2008/10/01
- 2008년 2학기 자료구조 - Flow Chart - mmult (3)2008/10/01
- 2008년 2학기 인간컴퓨터상호작용 - 2nd Homework (8)2008/09/26
글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.





003.pdf

댓글을 달아 주세요