这个是大一的代码,清理网盘,存为博客,仅供参考。
一、面向对象课程设计作品(基于MFC的仓库管理系统完整工程完整工程):
面向对象课程设计作品(完整)(也适用于软件工程大实验).7z_采用面向对象方法分析,设计和实现订货系统。-C/C++文档类资源-CSDN下载
二、实验四题目:
1. 运用指针或引用实现数据访问与参数传递,题目如下:
① 输入10个整数存入数组list,然后用指针法从后向前输出该数组中的整数。
#include<iostream> #include <iomanip> using namespace std; int main() { int *p, list[10]; for (int i = 0; i < 10; i++) { cout << "请输入一个数值\t" ; cin >> list[i]; } p = &list[0]; for(int a=9;a>=0;a--) { cout << setw(4) << *(p + a); } system("pause"); return 0; }
② 编写函数getlen计算字符串长度,形参使用指针或引用,函数返回值是字符串的长度(不包含字符串的结束标志),在主函数中调用并测试结果。
#include <iostream> using namespace std;//蓝多多作业 int getlen(char *p) { int a = 0; for (int i = 0; i < 1000; i++) { int j = p[i]; if (p[i] != 0) {a++;} else {break;} } return a; } int main() { char s[1000]; cin >> s; int b = getlen(s); cout << b << endl; system("pause"); return 0; }
③ 编写一个函数swap实现两个数据的互换,形参分别指针和引用,在调用并测试结果。
#include<iostream> #include <iomanip> using namespace std; void swap(int *P, int *q) { int n; n = *P; *P = *q; *q = n; } void swap1(int &y, int &z) { int x; x = y; y = z; z = x; } int main() { int a,b; cout << "请输入需要交换的两个数" << endl; cin >> a>>b; swap1(a,b); cout << "a=" << a <<setw(6)<< "b=" << b; cout << endl; swap(&a, &b); cout << "a=" << a << setw(6) << "b=" << b; system("pause"); return 0; }
2. 运用结构体组织复杂数据,参考题目如下:
① 定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天。
#include<iostream> #include <iomanip> using namespace std;//蓝多多作业 struct date { int month; int day; int year; }; int days(date a) { int i, m = 0, q; for (i = 1; i < a.month; i++) { switch (i) { case 1:q = 31; break; case 2:q = 28; break; case 3:q = 31; break; case 4:q = 30; break; case 5:q = 31; break; case 6:q = 30; break; case 7:q = 31; break; case 8:q = 31; break; case 9:q = 30; break; case 10:q = 31; break; case 11:q = 30; break; case 12:q = 31; break; } m += q; } m+=a.day; if (a.year%4 ==0&&a.year % 100 != 0 || a.year % 400 == 0) m++; return m; } int main() { date c; int a; cout << "请输入年份\t"; cin >> c.year; cout << "请输入月份\t"; cin >> c.month; cout << "请输入日子\t"; cin >> c.day; a = days(c); cout << "该日期是本年的第"<<setw(5)<<a<<setw(5)<<"天"; system("pause"); return 0; }
② 有5个学生,每个学生的资料包括学号、姓名、3门课的成绩,用赋初值的方法输入5个学生的数据到结构体数组中,输出每个学生3门课的平均成绩(保留2位小数)。输出格式为:
No name score1 score2 score3 average
101 Zhou 93 89 87 ------
102 Yang 85 80 78 ------
103 Chen 77 70 83 ------
104 Qian 70 67 60 ------
105 Li 72 70 69 ------
#include<iostream> #include <cmath> #include <iomanip>//蓝多多作业 using namespace std; struct chengji { int NO; char name[5]; int score1; int score2; int score3; };struct chengji a[5] = { {101,"zhou",93,89,87},{102,"yang",85,80,78},{103,"chen",77,70,83},{104,"qian",70,67,60},{105,"li",72,70,69} }; double average(int o,int p,int q) { float b; cout << fixed << setprecision(2); b=(o+p+q)/3.0; return b; } int main() { int x, y, z; struct chengji *p; cout << "NO" << setw(10) << "name" << setw(10) << "score1" << setw(10) << "score2" << setw(10) << "score3" << setw(10)<<"average"<<endl; p = a; for (; p <= a+4; p++) { cout << p->NO <<setw(9)<< p->name << setw(7) << p->score1 << setw(10) << p->score2 << setw(10) << p->score3 ; x = p->score1; y = p->score2; z = p->score3; cout<<setw(9)<<average(x,y,z); cout << endl; } system("pause"); return 0; }
③ 在上题中,按平均成绩由高到低排序,输出每个学生的成绩,输出格式与上题相同。
#include<iostream> #include <cmath> #include <iomanip>//蓝多多作业 using namespace std; struct chengji { int NO; char name[5]; int score1; int score2; int score3; double average; }; struct chengji a[5] = { {101,"zhou",93,89,87},{102,"yang",85,80,78},{103,"chen",77,70,83},{104,"qian",70,67,60},{105,"li",72,70,69} }; void swap(struct chengji *x, struct chengji *y)//交换函数 { struct chengji *t; t = x; x = y; y = t; } double average(int o, int p, int q) { double b; cout << fixed << setprecision(2); b = (o + p + q) / 3.0; return b; } int main() { int x, y, z; struct chengji *p; cout << "NO" << setw(10) << "name" << setw(10) << "score1" << setw(10) << "score2" << setw(10) << "score3" << setw(10) << "average" << endl; p = a; for (int i=0; p <= a + 4; p++,i++) { cout << p->NO << setw(9) << p->name << setw(7) << p->score1 << setw(10) << p->score2 << setw(10) << p->score3; x = p->score1; y = p->score2; z = p->score3; a[i].average=average(x, y, z); cout << setw(9) << average(x, y, z); cout << endl; } for (int j = 4; j >= 1; j--)//按平均成绩从大到小给结构体数组排序 { p = a; if (a[j].average > a[j - 1].average) swap(*(p + j), *(p + j - 1)); } for (int m = 0; m < 5; m++)//再按排序后的顺序输出 { cout << a[m].NO << "\t" << a[m].name << "\t" << a[m].score1 << "\t" << a[m].score2 << "\t" << a[m].score3 << "\t" << a[m].average << endl; } system("pause"); return 0; }