c++期末カリキュラム設計(単号題)

30845 ワード

期末コースの設計
 1 :            
      :  、  、     、  、    、    。
       ,      student.dat。
          ,    。
     ,          。
      、  、                 。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Student{
	string Name;
	int No;
	char Sex;
	int English;
	int Math;
	int Program;
	int PE;
public:
	Student(const string na = " ", int no = 0, char sex = 'm', int en = 0, int math = 0, int pro = 0, int pe = 0) :
		Name(na), No(no), Sex(sex), English(en), Math(math), Program(pro), PE(pe){
	}
	void setStudent(const string na, int no, char sex, int en, int math, int pro, int pe)
	{
		this->Name = na;
		this->No = no;
		this->Sex = sex;
		this->English = en;
		this->Math = math;
		this->Program = pro;
		this->PE = pe;
	}
	string getName()
	{
		return Name;
	}
	int getNo()
	{
		return No;
	}
	char getSex()
	{
		return Sex;
	}
	int getEnglish()
	{
		return English;
	}
	int getMath()
	{
		return Math;
	}
	int getProgram()
	{
		return Program;
	}
	int getPE()
	{
		return PE;
	}
	int getSum()
	{
		return English + Math + Program + PE;
	}
	int getClass()
	{
		return No / 100 % 10;
	}
	void show()
	{
		cout << Name << " " << No << " " << Sex << " " << English << " " << Math << " " << Program << " " << PE << " " << endl;
	}

};
bool cmpEnglish(Student a, Student b)
{
	return a.getEnglish()>b.getEnglish();
}
bool cmpMath(Student a, Student b)
{
	return a.getMath()>b.getMath();
}
bool cmpProgram(Student a, Student b)
{
	return a.getProgram()>b.getProgram();
}
bool cmpPE(Student a, Student b)
{
	return a.getPE()>b.getPE();
}
struct compare_name : binary_function
{
	bool operator()(Student &value, string str) const
	{
		if (value.getName() == str)
			return true;
		else
			return false;
	}
};
struct compare_no : binary_function
{
	bool operator()(Student &value, int a) const
	{
		if (value.getNo() == a)
			return true;
		else
			return false;
	}
};
void buildtable(vector &stu)
{
	ofstream outfile("student.txt", ios::out);
	if (!outfile){
		cout << "open error!" << endl;
		exit(1);
	}
	printf("      
"); int n; cin >> n; string na; int no; char sex; int en; int math; int pro; int pe; printf("
"); for (int i = 0; i> na >> no >> sex >> en >> math >> pro >> pe; outfile << na << " " << no << " " << sex << " " << en << " " << math << " " << pro << " " << pe << endl; Student s(na, no, sex, en, math, pro, pe); stu.push_back(s); } outfile.close(); printf(" !
"); } void findName(vector &stu) { printf("
"); string goal_name; cin >> goal_name; vector::iterator result_name = find_if(stu.begin(), stu.end(), bind2nd(compare_name(), goal_name)); // 3 if (result_name == stu.end()) cout << "Can't find" << endl; else { result_name->show(); } } void findNo(vector &stu) { printf("
"); int goal_no; cin >> goal_no; vector::iterator result_no = find_if(stu.begin(), stu.end(), bind2nd(compare_no(), goal_no)); // 3 if (result_no == stu.end()) cout << "Can't find" << endl; else { result_no->show(); } printf(" !
"); } void Average_score(vector &stu) { int sum[10] = { 0 }; int c[10] = { 0 }; vector::iterator iter; for (iter = stu.begin(); iter != stu.end(); iter++) { sum[iter->getClass()] += iter->getSum(); c[iter->getClass()]++; } for (int i = 0; i<10; i++) { if (sum[i] != 0) sum[i] /= c[i]; } for (int i = 0; i<10; i++) { if (sum[i] != 0) printf("Class %d:%d
", i, sum[i]); } printf(" !
"); } void sort_Score(vector &stu) { ofstream outfile_en("English.txt", ios::out); if (!outfile_en){ cout << "open error!" << endl; exit(1); } sort(stu.begin(), stu.end(), cmpEnglish); vector::iterator iter_en; for (iter_en = stu.begin(); iter_en != stu.end(); iter_en++) { outfile_en << iter_en->getName() << " " << iter_en->getNo() << " " << iter_en->getSex() << " " << iter_en->getEnglish() << " " << iter_en->getMath() << " " << iter_en->getProgram() << " " << iter_en->getPE() << endl; } outfile_en.close(); ofstream outfile_ma("Math.txt", ios::out); if (!outfile_ma){ cout << "open error!" << endl; exit(1); } sort(stu.begin(), stu.end(), cmpMath); vector::iterator iter_ma; for (iter_ma = stu.begin(); iter_ma != stu.end(); iter_ma++) { outfile_ma << iter_ma->getName() << " " << iter_ma->getNo() << " " << iter_ma->getSex() << " " << iter_ma->getEnglish() << " " << iter_ma->getMath() << " " << iter_ma->getProgram() << " " << iter_ma->getPE() << endl; } outfile_ma.close(); ofstream outfile_pro("Program.txt", ios::out); if (!outfile_pro){ cout << "open error!" << endl; exit(1); } sort(stu.begin(), stu.end(), cmpProgram); vector::iterator iter_pro; for (iter_pro = stu.begin(); iter_pro != stu.end(); iter_pro++) { outfile_pro << iter_pro->getName() << " " << iter_pro->getNo() << " " << iter_pro->getSex() << " " << iter_pro->getEnglish() << " " << iter_pro->getMath() << " " << iter_pro->getProgram() << " " << iter_pro->getPE() << endl; } outfile_pro.close(); ofstream outfile_pe("PE.txt", ios::out); if (!outfile_pe){ cerr << "open error!" << endl; exit(1); } sort(stu.begin(), stu.end(), cmpPE); vector::iterator iter_pe; for (iter_pe = stu.begin(); iter_pe != stu.end(); iter_pe++) { outfile_pe << iter_pe->getName() << " " << iter_pe->getNo() << " " << iter_pe->getSex() << " " << iter_pe->getEnglish() << " " << iter_pe->getMath() << " " << iter_pe->getProgram() << " " << iter_pe->getPE() << endl; } outfile_pe.close(); printf(" !
"); } int main() { printf("1.
"); printf("2.
"); printf("3.
"); printf("4.
"); printf("5. 、 、
"); printf("0.
"); vectorstu; while (1) { printf(" :
"); int c; scanf("%d", &c); switch (c) { case 1: buildtable(stu); continue; case 2: findNo(stu); continue; case 3: findName(stu); continue; case 4: Average_score(stu); continue; case 5: sort_Score(stu); continue; case 0: exit(1); } } return 0; } 3 :  : 0.02 / , 0.06 / , 1.00 / , 0.60 / , 0.50 / 。  : , , ( )。  : 。  : 。  : 。  : 。  : 。  : 、 。 #include #include #include #include #include #include #include using namespace std; class Price{ string Tel; float Expense; public: Price(string tel = "00000000000", float expense = 0) : Tel(tel), Expense(expense){} string getTel() { return Tel; } float getExpense() { return Expense; } void addExpense(string type, string time) { char str[20]; int h, m, s; time.copy(str, 8, 0); sscanf(str, "%d:%d:%d", &h, &m, &s); if (type == " ") { Expense += (h * 3600 + m * 60 + s)*0.02; } if (type == " ") { Expense += (h * 60 + m + 1)*0.06; } if (type == " ") { Expense += h * 60 + m + 1; } if (type == " ") { Expense += (h * 60 + m + 1)*0.6; } if (type == " ") { Expense += (h * 60 + m + 1)*0.5; } } }; struct compare : binary_function { bool operator()(Price &value, string str) const { if (value.getTel() == str) return true; else return false; } }; void statistics() { vectorphone_bill; ifstream f(" .txt"); if (!f) { cout << "open error!" << endl; } string str; while (getline(f, str)) { string tel, type, time; stringstream ss(str); ss >> tel; ss >> type; ss >> time; if (type == " ") { ofstream outfile(" .txt", ios::app); if (!outfile) { cout << "open error" << endl; } outfile << tel << " " << time << endl; outfile.close(); } if (type == " ") { ofstream outfile(" .txt", ios::app); if (!outfile) { cout << "open error" << endl; } outfile << tel << " " << time << endl; outfile.close(); } if (type == " ") { ofstream outfile(" .txt", ios::app); if (!outfile) { cout << "open error" << endl; } outfile << tel << " " << time << endl; outfile.close(); } if (type == " ") { ofstream outfile(" .txt", ios::app); if (!outfile) { cout << "open error" << endl; } outfile << tel << " " << time << endl; outfile.close(); } if (type == " ") { ofstream outfile(" .txt", ios::app); if (!outfile) { cout << "open error" << endl; } outfile << tel << " " << time << endl; outfile.close(); } vector::iterator result; result = find_if(phone_bill.begin(), phone_bill.end(), bind2nd(compare(), tel)); if (result == phone_bill.end()) { Price temp(tel, 0); temp.addExpense(type, time); phone_bill.push_back(temp); } else { result->addExpense(type, time); } } ofstream outfile(" .txt", ios::out); vector::iterator iter; for (iter = phone_bill.begin(); iter != phone_bill.end(); iter++) { outfile << iter->getTel() << " " << iter->getExpense() << endl; } } int main() { statistics(); cout << " !" << endl; return 0; } 5 :  : , , 。  : 1 *L m,n m n 2 *I m …… ^Z (……) m 3 *D m,n m n 4 *R m,n …… ^Z (……) m n 5 *X 6 *Q #include #include #include #include #include #include #include using namespace std; void initial(vector &text) { ifstream infile(" .txt"); if (!infile) { cout << "open error" << endl; exit(0); } string temp; while (getline(infile, temp)) { text.push_back(temp); } infile.close(); } void showtext(vector &text) { int m, n; scanf("%d,%d", &m, &n); printf(" %d %d :
", m, n); for (int i = m - 1; i &text) { int m; scanf("%d
", &m); int t = m; string temp; while (getline(cin, temp)) { if (temp == "^Z") break; text.insert(text.begin() + t, temp); t++; } for (int i = 0; i &text) { int m, n; scanf("%d,%d", &m, &n); text.erase(text.begin() + m - 1, text.begin() + n); for (int i = 0; i &text) { int m, n; scanf("%d,%d
", &m, &n); int t = m - 1; text.erase(text.begin() + t, text.begin() + n); string temp; while (getline(cin, temp)) { if (temp == "^Z") break; text.insert(text.begin() + t, temp); t++; } for (int i = 0; i &text) { ofstream outfile(" .txt", ios::out); if (!outfile) { cout << "open error" << endl; exit(0); } for (int i = 0; i &text) { initial(text); } int main() { vectortext; initial(text); for (int i = 0; i> command) { if (command == "*L") showtext(text); if (command == "*l") insert(text); if (command == "*D") Delete(text); if (command == "*R") Replace(text); if (command == "*X") SaveQuit(text); if (command == "*Q") Quit(text); } return 0; } 7 :  doublelong, : 64 ,  +、-、*、/  +=、-=、/=  cin >> cout << #include #include #define MAX 65*65 using namespace std; class doublelong{ char number[MAX]; public: doublelong(const char *str = " ") { strcpy(number, str); } void show() { cout << number << endl; } void operator>>(doublelong a) { cin >> number; } friend istream & operator>>(istream &is, doublelong &ob); friend ostream & operator<len2 ? len1 : len2; int ans[10] = { 0 }; for (i = 0; i= 0; i--) { if (ans[i] != 0) break; } if (i == -1) result[0] = '0'; else { int j; if (result[0] != '-') j = 0; else j = 1; while (i >= 0) { result[j] = ans[i] + '0'; j++; i--; } } } void add(char str1[], char str2[], char result[]) { int num1[MAX] = { 0 }, num2[MAX] = { 0 }; int len1 = strlen(str1); int len2 = strlen(str2); int i; for (i = 0; ilen2 ? len1 : len2; int ans[MAX] = { 0 }; for (i = 0; i= 10) { ans[i + 1] += ans[i] / 10; ans[i] = ans[i] % 10; } } for (i = len; i >= 0; i--) { if (ans[i] != 0) break; } int j; if (result[0] != '-') j = 0; else j = 1; while (i >= 0) { result[j] = ans[i] + '0'; j++; i--; } } void multiply(char str1[], char str2[], char result[]) { int num1[MAX] = { 0 }; int num2[MAX] = { 0 }; int ans[MAX] = { 0 }; int len1 = strlen(str1); int len2 = strlen(str2); int len = len1>len2 ? len1 : len2; int i, j; for (j = 0, i = len1 - 1; i >= 0; i--) num1[j++] = str1[i] - '0'; for (j = 0, i = len2 - 1; i >= 0; i--) num2[j++] = str2[i] - '0'; for (i = 0; i= 10) { ans[i + 1] = ans[i + 1] + ans[i] / 10; ans[i] = ans[i] % 10; } } for (i = len * 2; i>0; i--) { if (ans[i] != 0) break; } if (result[0] != '-') j = 0; else j = 1; while (i >= 0) { result[j] = ans[i] + '0'; j++; i--; } } int SubStract(int *p1, int *p2, int len1, int len2) { int i; if (len1= 0; i--) { if (p1[i]>p2[i]) break; else if (p1[i]= 0; i--) if (p1[i]) return i + 1; return 0; } void division(char str1[], char str2[], char result[]) { int i, j; int nTimes; int nTemp; int num1[MAX] = { 0 }; int num2[MAX] = { 0 }; int ans[MAX] = { 0 }; int len1 = strlen(str1); int len2 = strlen(str2); for (j = 0, i = len1 - 1; i >= 0; j++, i--) num1[j] = str1[i] - '0'; for (j = 0, i = len2 - 1; i >= 0; j++, i--) num2[j] = str2[i] - '0'; if (len1= 0; i--) { if (i >= nTimes) num2[i] = num2[i - nTimes]; else num2[i] = 0; } len2 = len1; for (j = 0; j <= nTimes; j++) { while ((nTemp = SubStract(num1, num2 + j, len1, len2 - j)) >= 0) { len1 = nTemp; ans[nTimes - j]++; } } for (i = 9; i >= 0; i--) { if (ans[i] != 0) break; } if (result[0] != '-') j = 0; else j = 1; while (i >= 0) { result[j] = ans[i] + '0'; j++; i--; } } istream & operator>>(istream &is, doublelong &ob) { is >> ob.number; return is; } ostream & operator<0) { result[0] = '-'; sub(str1 + 1, str2, result); } else { sub(str2, str1 + 1, result); } } else if (len1>len2) { result[0] = '-'; sub(str1 + 1, str2, result); } else { sub(str1 + 1, str2, result); } } else if (str1[0] != '-'&&str2[0] == '-') { int len1 = strlen(str1); int len2 = strlen(str2 + 1); if (len1 == len2) { if (strcmp(str1, str2 + 1)>0) { sub(str1, str2 + 1, result); } else { result[0] = '-'; sub(str2 + 1, str1, result); } } else if (len10) { sub(str1, str2, result); } else { result[0] = '-'; sub(str2, str1, result); } } else if (len1>len2) { sub(str1, str2, result); } else { result[0] = '-'; sub(str1, str2, result); } } else { int len1 = strlen(str1 + 1); int len2 = strlen(str2 + 1); if (len1 == len2) { if (strcmp(str2 + 1, str1 + 1) >= 0) { sub(str2 + 1, str1 + 1, result); } else { result[0] = '-'; sub(str1 + 1, str2 + 1, result); } } else if (len1>len2) { result[0] = '-'; sub(str1 + 1, str2 + 1, result); } else { sub(str1 + 1, str2 + 1, result); } } return doublelong(result); } doublelong operator*(doublelong &ob1, doublelong &ob2) { char result[MAX]; char str1[MAX], str2[MAX]; strcpy(str1, ob1.number); strcpy(str2, ob2.number); if (strcmp(str1, "0") == 0 || strcmp(str2, "0") == 0) { return doublelong("0"); } if (str1[0] != '-'&&str2[0] == '-') { result[0] = '-'; multiply(str1, str2 + 1, result); } else if (str1[0] == '-'&&str2[0] != '-') { result[0] = '-'; multiply(str1 + 1, str2, result); } else if (str1[0] == '-'&&str2[0] == '-') { multiply(str1 + 1, str2 + 1, result); } else { multiply(str1, str2, result); } return doublelong(result); } doublelong operator/(doublelong &ob1, doublelong &ob2) { char result[MAX]; char str1[MAX], str2[MAX]; strcpy(str1, ob1.number); strcpy(str2, ob2.number); if (str1[0] != '-'&&str2[0] == '-') { result[0] = '-'; division(str1, str2 + 1, result); } else if (str1[0] == '-'&&str2[0] != '-') { result[0] = '-'; division(str1 + 1, str2, result); } else if (str1[0] == '-'&&str2[0] == '-') { division(str1 + 1, str2 + 1, result); } else { division(str1, str2, result); } return doublelong(result); } void doublelong::operator+=(doublelong &ob) { char result[MAX]; char str1[MAX], str2[MAX]; strcpy(str1, this->number); strcpy(str2, ob.number); if (str1[0] == '-'&&str2[0] == '-') { result[0] = '-'; add(str1 + 1, str2 + 1, result); } else if (str1[0] == '-'&&str2[0] != '-') { int len1 = strlen(str1 + 1); int len2 = strlen(str2); if (len1 == len2) { if (strcmp(str1 + 1, str2)>0) { result[0] = '-'; sub(str1 + 1, str2, result); } else { sub(str2, str1 + 1, result); } } else if (len1>len2) { result[0] = '-'; sub(str1 + 1, str2, result); } else { sub(str1 + 1, str2, result); } } else if (str1[0] != '-'&&str2[0] == '-') { int len1 = strlen(str1); int len2 = strlen(str2 + 1); if (len1 == len2) { if (strcmp(str1, str2 + 1)>0) { sub(str1, str2 + 1, result); } else { result[0] = '-'; sub(str2 + 1, str1, result); } } else if (len1number, result); } void doublelong::operator-=(doublelong &ob) { char result[MAX]; char str1[MAX], str2[MAX]; strcpy(str1, this->number); strcpy(str2, ob.number); if (str1[0] != '-'&&str2[0] == '-') { add(str1, str2 + 1, result); } else if (str1[0] == '-'&&str2[0] != '-') { result[0] = '-'; add(str1 + 1, str2, result); } else if (str1[0] != '-'&&str2[0] != '-') { int len1 = strlen(str1); int len2 = strlen(str2); if (len1 == len2) { if (strcmp(str1, str2)>0) { sub(str1, str2, result); } else { result[0] = '-'; sub(str2, str1, result); } } else if (len1>len2) { sub(str1, str2, result); } else { result[0] = '-'; sub(str1, str2, result); } } else { int len1 = strlen(str1 + 1); int len2 = strlen(str2 + 1); if (len1 == len2) { if (strcmp(str2 + 1, str1 + 1) >= 0) { sub(str2 + 1, str1 + 1, result); } else { result[0] = '-'; sub(str1 + 1, str2 + 1, result); } } else if (len1>len2) { result[0] = '-'; sub(str1 + 1, str2 + 1, result); } else { sub(str1 + 1, str2 + 1, result); } } strcpy(this->number, result); } void doublelong::operator/=(doublelong &ob) { char result[MAX]; char str1[MAX], str2[MAX]; strcpy(str1, this->number); strcpy(str2, ob.number); if (str1[0] != '-'&&str2[0] == '-') { result[0] = '-'; division(str1, str2 + 1, result); } else if (str1[0] == '-'&&str2[0] != '-') { result[0] = '-'; division(str1 + 1, str2, result); } else if (str1[0] == '-'&&str2[0] == '-') { division(str1 + 1, str2 + 1, result); } else { division(str1, str2, result); } strcpy(this->number, result); } int main() { doublelong a = "100", b = "-7", c; c = a*b; cout << c << endl; c = "0"; cout << c << endl; return 0; } 9 : (vc++、vs )  , 、 、 、 、 ;  , , 、 , 。 #include #include #include #include using namespace std; #define j2h(x) (3.1415926*(x)/180.0) class Point{ int x, y; public: Point(int x = 0, int y = 0) :x(x), y(y){ } int getx() { return x; } int gety() { return y; } void setPoint(int xx = 0, int yy = 0) { x = xx; y = yy; } void show() { printf("Point:(%d,%d)
", x, y); } }; class Line{ Point a; Point b; public: Line(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0) :a(x1, y1), b(x2, y2){ } void show() { printf("Line:(%d,%d)--(%d,%d)
", a.getx(), a.gety(), b.getx(), b.gety()); } }; class rectangle{ Point a, b, c, d; public: rectangle(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0, int x3 = 0, int y3 = 0, int x4 = 0, int y4 = 0) : a(x1, y1), b(x2, y2), c(x3, y3), d(x4, y4){ } Point getlefttopPoint() { return a; } Point getrightbottomPoint() { return d; } void setRectangle(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0, int x3 = 0, int y3 = 0, int x4 = 0, int y4 = 0) { a.setPoint(x1, y1); b.setPoint(x2, y2); c.setPoint(x3, y3); d.setPoint(x4, y4); } void show() { printf("Rectangle:(%d,%d),(%d,%d),(%d,%d),(%d,%d)
", a.getx(), a.gety(), b.getx(), b.gety(), c.getx(), c.gety(), d.getx(), d.gety()); } }; class Circle{ protected: Point a; int r; public: Circle(int x1 = 0, int y1 = 0, int rr = 0) :a(x1, y1), r(rr){ } void show() { printf("Circle:
"); printf(" :(%d,%d), %d
", a.getx(), a.gety(), r); } }; class Sector :public Circle{ int ca; public: Sector(int x = 0, int y = 0, int r = 0, int ca = 0) :Circle(x, y, r), ca(ca){ } void show() { printf(" :(%d,%d)
:%d
:%d
", a.getx(), a.gety(), r, ca); } float getcx() { if (ca <= 90 && ca >= 0) return 725 + r*cos(j2h(ca)); if (ca <= 360 && ca>270) return 725 + r*cos(j2h(360 - ca)); if (ca>90 && ca <= 180) return 725 - r*cos(j2h(180 - ca)); if (ca > 180 && ca <= 270) return 725 - r*cos(j2h(ca - 180)); } float getcy() { if (ca <= 180 && ca >= 0) return 75 - r*sin(j2h(ca)); if (ca>180 && ca <= 360) return 75 + r*sin(j2h(ca - 180)); } }; class Linechart{ float a[5]; HDC hdc; PAINTSTRUCT ps; public: Linechart(float a[], HDC hdc, PAINTSTRUCT ps) :hdc(hdc), ps(ps){ int n = sizeof(a) / sizeof(float); for (int i = 0; i < 5; i++) { this->a[i] = a[i]; } } void draw(){ Point s[5]; int x = 50; for (int i = 0; i<5; i++) { s[i].setPoint(x, (int)(150 - a[i] * 50)); x += 50; } MoveToEx(hdc, 50, 150, NULL); LineTo(hdc, 250, 150); MoveToEx(hdc, 50, 150, NULL); LineTo(hdc, 50, 0); MoveToEx(hdc, 50, 0, NULL); LineTo(hdc, 45, 5); MoveToEx(hdc, 50, 0, NULL); LineTo(hdc, 55, 5); MoveToEx(hdc, 250, 150, NULL); LineTo(hdc, 245, 155); MoveToEx(hdc, 250, 150, NULL); LineTo(hdc, 245, 145); for (int i = 1; i<5; i++) { MoveToEx(hdc, s[i - 1].getx(), s[i - 1].gety(), NULL); LineTo(hdc, s[i].getx(), s[i].gety()); } } }; class Barchart{ float a[3]; HDC hdc; PAINTSTRUCT ps; public: Barchart(float a[], HDC hdc, PAINTSTRUCT ps) :hdc(hdc), ps(ps){ for (int i = 0; i < 3; i++) { this->a[i] = a[i]; } } void draw() { rectangle s[3]; int x = 350; for (int i = 0; i<3; i++) { s[i].setRectangle(x, (int)(150 - a[i] * 50), x + 50, (int)(150 - a[i] * 50), x, 150, x + 50, 150); x += 50; } MoveToEx(hdc, 350, 150, NULL); LineTo(hdc, 550, 150); MoveToEx(hdc, 350, 150, NULL); LineTo(hdc, 350, 0); MoveToEx(hdc, 350, 0, NULL); LineTo(hdc, 345, 5); MoveToEx(hdc, 350, 0, NULL); LineTo(hdc, 355, 5); MoveToEx(hdc, 550, 150, NULL); LineTo(hdc, 545, 155); MoveToEx(hdc, 550, 150, NULL); LineTo(hdc, 545, 145); for (int i = 0; i < 3; i++) { Rectangle(hdc, s[i].getlefttopPoint().getx(), s[i].getlefttopPoint().gety(), s[i].getrightbottomPoint().getx(), s[i].getrightbottomPoint().gety()); } } }; class Fanchart{ int ca; HDC hdc; PAINTSTRUCT ps; public: Fanchart(int ca, HDC hdc, PAINTSTRUCT ps) :ca(ca), hdc(hdc), ps(ps){ } void draw() { Sector s(1, 1, 2, ca); Pie(hdc, 650, 0, 800, 150, s.getcx(), s.getcy(), 800, 75); } }; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); //window procedure. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("Mywindow"); HWND hwnd; MSG msg; WNDCLASS wndClass; //The window Class wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc;// assign the window procedure to windows class. wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = szAppName; //Register the Window Class to the Windows System. if (!RegisterClass(&wndClass)) { MessageBox(NULL, TEXT("This program require Windows NT!"), szAppName, MB_ICONERROR); return 0; } //This function will generate an WM_CREATE message. hwnd = CreateWindow(szAppName, //Window class name TEXT("Mywindow"), //Window caption WS_OVERLAPPEDWINDOW, //Window Style CW_USEDEFAULT, //initial x position CW_USEDEFAULT, //initial y position CW_USEDEFAULT, //initial x size CW_USEDEFAULT, //initial y size NULL, //parent window handle NULL, //window menu handle hInstance, //program instance handle NULL); //creation parameters ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); //This function will generate a WM_PAINT message. /* The message loop for this program. if received the WM_QUIT message, the function will return 0.*/ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } //define the Window Procedure WndProc LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; float a[] = { 1, 2, 0.5, 1, 0.5 }; float b[] = { 1, 2.5, 2 }; int angle = 90; switch (message) //get the message { case WM_CREATE: return 0; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); Linechart lc(a, hdc, ps); lc.draw(); Barchart bc(b, hdc, ps); bc.draw(); Fanchart fc(360 - angle, hdc, ps); fc.draw(); EndPaint(hwnd, &ps); return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }