1、 C+语言程序设计课程设计语言程序设计课程设计 一、一、 实习题目:实习题目: 设计菜单选择程序 二、二、 设计思想:设计思想: 1、实现循环和功能选择:编写一个菜单函数 menu(),用 whlie 循环 控制菜单的重复选择,用 switch 语 句对应用户的选择,并且实现 相应的功能。 2、设计各个选择的功能:对于选择 1,运用克莱姆法则求解线性方程 组,用了多个循环和 if 判断语句, 其中两个函数调用,其主要功 能是求解行列式的数值; 选择二,统计一篇英语文章的单词数, 使用了函数 getchar( ) 和 gets(str),用于输入英文文章。 三、三、 程序代码:程序代码: #in
2、clude #include using namespace std; #define N 10000 void menu();/菜单选项函数 void equation();/求线性方程组 void english();/统计英文文章的单词数 /主函数的执行/ int main() int a,t=1; while(t) menu(); coutn; coutaij; cinbi; d=det(n); for (j=0;jch; if(ch=y|ch=Y) goto A; else if(ch=n|ch=N) goto C; else goto B; C:system(“pause“); /
3、统计英文文章的单词数/ void english() char strN,c; int i,word=0,num=0; coutcn; while(cn4); return cn; /显示职工信息的完整记录/ void list:display () coutan.num; if(an.num=“0“) break; /结束输入 for(int k=0;kan.name; for(k=0;kan.sex; if(an.sex!=f coutan.age; /2.生成信息简表/ float creat(list y,simplelist x,int i(istream friend ostrea
4、m 输入输出就是按格式构造输出,输入流需要保证正确的格式,要 保证分母不等于零。 三、三、 程序代码:程序代码: #include using namespace std; class Rational /有理数类 public: int x; int y; Rational(int x1=0,int y1=1)x=x1;y=y1; Rational operator+(Rational r); /重载加法运算符 Rational operator-(Rational r); /重载减法运算符 Rational operator*(Rational r); /重载乘法运算符 Rational
5、operator/(Rational r); /重载除法运算符 friend istream /重载输入运算符 friend ostream /重载输出运算 符 ; /主函数的执行/ 有理数的四则运算有理数的四则运算 报告报告3 int main() char ch; Rational A,B,C; A:coutA; coutB; coutch; cout=y,且 x,y有公约数时,进行约分 for(i=r.y;i1;i-) if(r.x%i=0 n=r.y/i; r.x=m; r.y=n; outr.x“/“r.yendl; /以分数的形式输出计算结果 return out; Rational Rational:operator+(Rational r) return Rational(x*r.y+y*r.x,y*r.y); Rational Rational:operator-(Rational r) return Rational(x*r.y-y*r.x,y*r.y); Rational Rational:operator*(Rational r) return Rational(x*r.x,y*r.y); Rational Rational: