作业帮 > 综合 > 作业

写一个c 程序 Write a C program

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/14 18:58:41
写一个c 程序 Write a C program
Write a C program that receives from the command line a student ID (SXXXXX) to be used as a reference.Then the program asks the user to introduce the information about the results obtained by a set of students in the final examination (maximum 100,however,the user may introduce a lower number of entries).The input format must be the following:
 NAME LASTNAME student_ID MARK
In the case the reference ID is introduced in the provided list,the program must compute how many students obtained lower and higher marks compared to the reference one.
#include<iostream>
#define MAXSIZE 100
using namespace std;
struct Student
{
char name[20];
char last_name[20];
int ID;
int mark;
};
class list
{
private:
Student stu[MAXSIZE];
int len;
public:
void input();
void sort();
};
void list::input()
{
cout<<"How many students do you want to input?"<<endl;
cin>>len;
for(int i=1;i<=len;i++)
{
cout<<"Input name"<<endl;
cin>>stu[i].name;
cout<<"Input last_name"<<endl;
cin>>stu[i].last_name;
cout<<"Input ID"<<endl;
cin>>stu[i].ID;
cout<<"Input mark"<<endl;
cin>>stu[i].mark;
}
}
void list::sort()
{
int ID1,lower=0,higher=0;
cout<<"Please Input the reference ID(1<=ID<=The total number of Student)"<<endl;
cin>>ID1;
for(int i=1;i<=len;i++)
{
if(stu[ID1].mark>stu[i].mark)
lower++;
if(stu[ID1].mark<stu[i].mark)
higher++;
}
cout<<"There're "<<lower<<"  Students' mark lower than reference ID's Student."<<endl;
cout<<"There're "<<higher<<"  Students' mark higher than reference ID's Student."<<endl;
}
void main()
{
list stu;
stu.input();
stu.sort();
}Successful operation in VC6.0