일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- System
- Sort
- array
- function
- 포인터
- UTF-8
- OOP
- java
- algorithm
- 윈도우즈
- windows
- c++
- jsp
- request
- CLASS
- JavaScript
- CSS
- 악성코드
- 노드
- C
- meta
- HTML
- Kafka
- beans
- query
- Call-by-reference
- WebProgramming
- 투자
- API
- 자료구조
- Today
- Total
hahahia
5주차 객체 과제 본문
5.10
#include <iostream>
using namespace std;
int main()
{
int result=1;
for(int i=1; i<=5; i++)
{
for (int j=1; j <= i; j++)
{
result *= j;
}
cout<< i << "! " <<result<<endl;
result = 1;
}
return 0;
} // 팩토리얼 출력
5.15
#include <iostream>
#include <string>
using namespace std;
class GradeBook
{
private:
string courseName;
int aCount;
int bCount;
int cCount;
int dCount;
int fCount;
public:
GradeBook (string);
void setCourseName (string);
string getCourseName ();
void displayMessage();
void inputGrades();
void displayGradeReport();
};
GradeBook::GradeBook(string name)
{
setCourseName(name);
aCount=0;
bCount=0;
cCount=0;
dCount=0;
fCount=0;
}
void GradeBook::setCourseName(string name)
{
if (name.length() <= 25)
courseName=name;
else
{
courseName = name.substr (0,25);
cout<<"Name\""<<name<<"\" exceeds m,aximum length (25).\n"<<"Limiting courseName to first 25 characters.\n"<<endl;
}
}
string GradeBook::getCourseName()
{
return courseName;
}
void GradeBook::displayMessage()
{
cout<<"Welcome to the grade book for\n"<<getCourseName()<<"!\n"<<endl;
}
void GradeBook::inputGrades()
{
int grade;
cout<<"Enter the letter grades."<<endl<<"Enter the EOF charcter to end input"<<endl;
while ( ( grade = cin.get() ) != EOF )
{
switch ( grade )
{
case 'A':
case 'a':
aCount++;
break;
case 'B':
case 'b':
bCount++;
break;
case 'C':
case 'c':
cCount++;
break;
case 'D':
case 'd':
dCount++;
break;
case 'F':
case 'f':
fCount++;
break;
case '\n':
case '\t':
case ' ':
break;
default:
cout<<"Incorrect letter grade entered."<<"Enter a new grade."<<endl;
break;
}
}
}
void GradeBook::displayGradeReport()
{
cout<<"\n\nNumber of students who received each letter grade.\n"
<<"\nA: "<<aCount
<<"\nB: "<<bCount
<<"\nC: "<<cCount
<<"\nD: "<<dCount
<<"\nF: "<<fCount
<<endl;
cout<<"Grade average : "<<(double)(4*aCount+3*bCount+2*cCount+1*dCount+0*fCount)/(aCount+bCount+cCount+dCount+fCount)<<endl;
}
int main()
{
GradeBook myGradeBook( " CS101 C++ Programming ");
myGradeBook.displayMessage();
myGradeBook.inputGrades();
myGradeBook.displayGradeReport();
} // class를 이용한 성적입력후 학점평균계산 프로그램
5.19
#include <iostream>
using namespace std;
int main()
{
double a=4;
double t=0;
for(double i=1; i<=1000; i++)
{
if((int)i%2==1)
{
a = a - (4 / (2*i+1));
}
else
{
a = a + (4 / (2*i+1));
}
}
cout << a << endl;
return 0; // π값 계산
}
5.23
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "input a : " ;
cin >> a ;
for(int i=0; i<a; i++)
{
for(int j=a-i; j>0; j--)
{
cout << " ";
}
for(int k=0; k<=i*2; k++)
{
cout << "*";
}
cout << endl;
}
for(int i=0; i<a-1; i++)
{
for(int j=a-i-2; j<=a-1; j++)
{
cout << " " ;
}
for(int k=0; k<2*(a-1-i)-1; k++)
{
cout << "*";
}
cout << endl;
}
return 0;
} // diamond 모양 출력
5.29
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double amount;
double principal = 24.0;
double rate = .05;
for (int i = 0; i<=5; i++)
{
for ( int year=1; year <= 384; year++)
{
amount = principal * pow ( 1.0 + rate, year);
}
cout << fixed << setprecision( 2 );
cout << rate*100 << "% = "<< amount << endl;
rate += .01;
amount = 0;
} // 원리합계
}
'Language > C++' 카테고리의 다른 글
Operator Overloading(연산자 오버로딩) (0) | 2012.09.01 |
---|---|
1주차 (0) | 2011.06.27 |
Class GradeBook Using an Array to Store Grades (0) | 2011.05.25 |
재귀함수를 이용한 fibonacci (0) | 2011.05.17 |
간단한 Class프로그램을통한 Class의 개념과 특징 (0) | 2011.05.10 |