3.1.1设计题目及要求
课题内容:
设计一个分数统计程序。包括学生信息的输入输出以及排序。通过该课题全面熟悉数组、字符串、文件的使用,掌握程序设计的基本方法及友好界面的设计。
课题要求:
(1)输入某班级学生的姓名、分数;
(2)对(1)的分数进行降幂排列并输出;
(3)具有输入输出界面。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct student
{
char name[10];
float score;
}stu[200];
int comp(const student &a,const student &b)
{
return a.score > b.score;
}
void Menu();
void Choose();
void Input();
void Output();
void Sort();
void Number();
int num;
int main()
{
while (1)
{
int i;
char ch;
Menu();
Choose();
ch=getchar();
}
}
void Menu()
{
getchar();
cout<<"\t\t*********************************\t\t"<<endl;
cout<<"\t\t********班级成绩排序系统*********\t\t"<<endl;
cout<<"\t\t********输入成绩请按 1***********\t\t"<<endl;
cout<<"\t\t********显示成绩请按 2***********\t\t"<<endl;
cout<<"\t\t********成绩降序请按 3***********\t\t"<<endl;
cout<<"\t\t********退出界面请按 4***********\t\t"<<endl;
}
void Choose()
{
int choice;
do cin>>choice;
while(choice<1||choice>4);
switch(choice)
{
case 1: Number();Input();break;
case 2: Output();break;
case 3: Sort();Output();;break;
case 4: exit(1);
}
}
void Number()
{
cout<<"\t\t请输入班级人数:\t\t"<<endl;
cin>>num;
cout<<"\n";
}
void Input()
{
int i=0;
for(i=0;i<num;i++)
{
cout<<"\t\t姓名:\t\t"<<endl;
cin>>stu[i].name;
cout<<"\t\t分数\t\t"<<endl;
cin>>stu[i].score;
cout<<"\n";
}
}
void Output()
{
int i=0;
cout<<"\t\t班级学生成绩如下:\t\t"<<endl;
cout<<"\t\t姓名\t\t成绩 \t\t"<<endl;
for(i=0;i<num;i++)
{
cout<<"\t\t"<<stu[i].name<<"\t\t"<<stu[i].score<<"\t\t"<<endl;
}
}
void Sort()
{
sort(stu+0,stu+num,comp);
}
3.2.1设计题目及要求
课题内容:
设计一个打字程序。包括随机产生字符串,以及字符串比较和统计。通过此课题,熟练掌握数组、格式输出、字符串处理等。
课题要求:
(1)随机产生一字符串,每次产生的字符串内容、长度都不同;
(2)根据(1)的结果,输入字符串,判断输入是否正确,输出正确率;
(3)具有输入输出界面。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <time.h>
using namespace std;
const int N=20;
char ch,a[N],b[N];
void Menu();
void Choose();
void Genrnd(char *a,int length);
void Input(char *b);
void Judge(char *a,char *b);
int i,length;
double j;
double k=0.0;
int main()
{
while(1)
{
char ch;
Menu();
Choose();
ch=getchar();
}
}
void Menu()
{
getchar();
cout<<"\t\t********打 字 系 统 ***********\t\t"<<endl;
cout<<"\t\t*****************************************\t\t"<<endl;
cout<<"\t\t*****************************************\t\t"<<endl;
cout<<"\t\t********随机生成字符串 请按 1***********\t\t"<<endl;
cout<<"\t\t********输入字符串 请按 2***********\t\t"<<endl;
cout<<"\t\t********查看正确率 请按 3***********\t\t"<<endl;
cout<<"\t\t********退出界面 请按 4***********\t\t"<<endl;
cout<<"\t\t*****************************************\t\t"<<endl;
}
void Choose()
{
int choice;
do cin>>choice;
while(choice<1||choice>4);
switch(choice)
{
case 1: Genrnd(a,length) ;break;
case 2: Input(b);break;
case 3: Judge(a,b);break;
case 4: exit(1);
}
}
void Genrnd(char *a,int