录入每个学生的学号和考试成绩
Ⅰ 编写一个程序,输入每个学生的学号和平均成绩,将平均成绩按递减顺序排序,输出排序后的学号和平均成绩。
#include <iostream>
#include <iomanip>
struct student
{int num;
char name[20];
float score[3];
};
void average_print(student *);
void top_print(student *);
void top1_print(student *);
void top2_print(student *);
void top3_print(student *);
int main()
{ student stu[3],*p;
int i;
cout<<"请输入3个学生数据:"<<endl;
for(i=0;i<3;++i)
{cin>>stu[i].num>>stu[i].name>>stu[i].score[0]>>stu[i].score[1]>>stu[i].score[2];
}
average_print(stu) ;
int z ;
do
{cout<<"请选择相应选项:"<<endl;
cout<<"1:第一门课最高分数的信息"<<endl;
cout<<"2:第二门课最高分数的信息"<<endl;
cout<<"3:第三门课最高分数的信息"<<endl;
cout<<"4:总分最高分数的信息"<<endl;
cin>>z;
switch(z)
{ case 1:top_print(stu) ;break;
case 2:top1_print(stu) ;break;
case 3:top2_print(stu) ;break;
default:top3_print(stu) ;break;
}
}while(z!=0);
return 0;
}
void average_print(student p[])
{ float x=0,y=0,z=0;
int i;
for(i=0;i<3;++i)
{ x+=p[i].score[0];
y+=p[i].score[1];
z+=p[i].score[2];
}
cout<<"第一门课平均成绩"<<x/3<<endl;
cout<<"第二门课平均成绩"<<y/3<<endl;
cout<<"第三门课平均成绩"<<x/3<<endl;
}
void top_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[0];
for(i=1;i<3;++i)
{ if(j<=point[i].score[0] )
{j=point[i].score[0];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[0]<<endl;
}
void top1_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[1];
for(i=1;i<3;++i)
{ if(j<=point[i].score[1] )
{j=point[i].score[1];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[1]<<endl;
}
void top2_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[2];
for(i=1;i<3;++i)
{ if(j<=point[i].score[2] )
{j=point[i].score[2];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[2]<<endl;
}
void top3_print(student point[])
{int i,z;
float j;
student temp ;
temp=point[0];
j=point[0].score[0]+point[0].score[1]+point[0].score[2];
for(i=1;i<3;++i)
{ if(j<=point[i].score[0]+point[i].score[1]+point[i].score[2])
{j=point[i].score[0]+point[i].score[1]+point[i].score[2];
temp= point[i];}
}
cout<<"这门课最高分为:"<<temp.num<<setw(6)<<temp.name<<setw(6)<<temp.score[2]+temp.score[0]+temp.score[1]<<endl;
}
Ⅱ 找高手帮忙c语言程序::输入一个班10个学生的学号和每个学生考试三门功课(数学、英语、计算机基础)的成绩
刚学完链表,现学现卖~(自己写的,需要注释再给你填上~)
#include "stdio.h"
#define N 10
struct student{
int number;
int sx;
int yy;
int jsj;
struct *next;
};
void main()
{
struct student *p,*q,*head;
int i=0,j,temp;
int a[N],b[N];
head=NULL;
q=NULL;
while(i<N){
p=(struct student *)malloc(sizeof(struct student));
printf("请输入第%d名同学的学号",i+1);
scanf("%d",&p->number);
printf("请输入第%d名同学的数学成绩",i+1);
scanf("%d",&p->sx);
printf("请输入第%d名同学的英语成绩",i+1);
scanf("%d",&p->yy);
printf("请输入第%d名同学的计算机成绩",i+1);
scanf("%d",&p->jsj);
a[i]=((p->jsj)+(p->sx)+(p->yy));
b[i]=a[i]/3;
if(head==NULL){
head=p;
}
q=p->next;
p=p->next;
i++;
}
for(i=0;i<N;i++)
for(j=0;j<5;j++){
if(a[j]<a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+i]=temp;
}
}
for(i=0;i<N;i++){
printf("第%d名同学总分为%d\n",i+1,a[i]);
}
}
Ⅲ 编写程序,输入10个学生的学号,姓名和考试成绩,输出最高分和最低分的学生记录
你好! 按照你的题目写了这个代码,可以的话请采纳
代码可以直接复制出来测试(linux系统)
#include<stdio.h>
#include<sting.h>
struct student{
int ID;//学号
char Name[50];//姓名
int Grade;//成绩
};
void main()
{
struct student stu[100];
int i = 0;
int n,m;
int big;
int small;
while(1)
{
printf("请输入学生的姓名、学号、成绩以空格隔开:\n");
printf("结束请输入exit 0 0\n");
scanf("%s%d%d",stu[i].Name,&stu[i].ID,&stu[i].Grade);//接收输入的学生信息
printf("%d\n",stu[i].Grade);
//判断是否要结束输入
if(strcmp(stu[i].Name,"exit") == 0)
{
printf("输入结束\n");
i = i - 1;
break;
}
i++;
}
if(i == 0)
{
printf("只输入了一个学生的信息\n");
return;
}
//循环进行比较记录最高和最低
//big、small记录第0个元素的分数
big = stu[0].Grade;
small = stu[0].Grade;
for(n = 1;n <= i;n++)
{
printf("grade = %d\n",stu[n].Grade);
if(big < stu[n].Grade)
{
big = stu[n].Grade;//big和各个元素的分数比较,取较高赋值给big(big一直为较高)
}
if(small > stu[n].Grade)
{
small = stu[n].Grade;//small和各个元素的分数比较,取较低赋值给small(small一直为较低)
}
}
for(m = 0;m <= i;m++)
{
printf("xx:%d,%s,%d\n",stu[m].ID,stu[m].Name,stu[m].Grade);
if(stu[m].Grade == big)//每个学生的成绩和最高分比较,相等的输出(可能会出现并列的)
{
printf("最高分数学生信息:%d,%s,%d\n",stu[m].ID,stu[m].Name,stu[m].Grade);
}
if(stu[m].Grade == small)//每个学生的成绩和最低分比较,相等的输出(可能会出现并列的)
{
printf("最低分数学生信息:%d,%s,%d\n",stu[m].ID,stu[m].Name,stu[m].Grade);
}
}
}
Ⅳ 编程题:输入10个考生的学号和某门课的考试分数(0-100),然后根据每个学生的分数判断并显示每个学生的
#include <stdio.h>
int main()
{
int num,score;
char grade;
scanf("%d",&num);
do
{
scanf("%d",&score);
if(score < 0 || score > 100)
{
printf("学号为%d的考生专成属绩输入错\n",num);
continue;
}
if(score<60)
grade = 'F';
else if(score<70)
grade = 'D';
else if(score<80)
grade = 'C';
else if(score<90)
grade = 'B';
else
grade = 'A';
break;
}while(1);
printf("学号为%d的考生成绩为%c\n",num,grade);
return 0;
}
Ⅳ 急求!!C语言程序:输入一个班10个学生的学号和每个学生考试三门功课(数学、英语、计算机基础)的成绩。
#include <string.h>
#include<iostream>
using namespace std;
class Stu
{
int number;
char name[20];
double math;
double english;
double computer;
public:
Stu(int x,double b1,double b2,double b3,char *p)
{
number=x;
strcpy(name,p);
math=b1;
english=b2;
computer=b3;
};
double sum();
double average();
void print();
int get_reg_num();
void get_stu_inf();
};
double Stu::sum()
{
return(math+english+computer);
}
double Stu::average()
{ double n;
n=(math+english+computer)/3;
return(n);
}
void Stu::print()
{
cout<<"学号"<<'\t'<<"姓名"<<'\t'<<" 数学成绩"<<'\t'<<" 英语成绩"<<'\t'<<"计算机成绩"<<endl;
cout<<number<<'\t'<<name<<'\t'<<'\t'<<math<<'\t'<<'\t'<<english<<'\t'<<'\t'<<computer<<endl;
}
int Stu::get_reg_num()
{
return(number);
}
void Stu::get_stu_inf()
{
cout<<"请输入学生名称";
cin>>name;
cout<<"请输入学生学号";
cin>>number;
cout<<"请输入学生数学成绩";
cin>>math;
cout<<"请输入学生英语成绩";
cin>>english;
cout<<"请输入学生计算机成绩";
cin>>computer;
}
int main()
{
int i,number,c=0;
double s=0;
double y=0;
Stu a[3]={Stu(3450,85,75,65,"yang"),Stu(3440,85,75,65,"hehe"),Stu(3450,85,75,65,"hei")};
for(i=0;i<3;i++)
{
a[i].print();
}
for(i=0;i<3;i++)
{
s=s+a[i].average();
y=y+a[i].sum();
cout<<a[i].get_reg_num()<<endl;
cout<<"平均成绩";
cout<<a[i].average()<<endl;
cout<<"总成绩";
cout<<a[i].sum()<<endl;
}
cout<<"全班总分"<<s<<endl;
cout<<"全班平均成绩"<<y/3<<endl;
cout<<"请输入要查询的学号";
cin>>number;
for(i=0;i<3;i++)
{
if(number==a[i].get_reg_num())
{
a[i].print();
c++;
}
}
if(c==0)
cout<<"没有找到相关学生信息";
system("pause");
return 0;
}
这是以前写的一段代码,自己改下吧
Ⅵ 通过键盘输入20个学生的学号和考试成绩,显示出所有高于平均分的学生的学号和成绩
#include<stdio.h>
structStudent{
charnum[24];
intfenshu;
};
voidmain()
{
inti,sum=0;
Studentstu[20];
for(i=0;i<20;i++)
{
printf("请输入抄第袭%d个学生的学号:",i+1);
scanf("%s",stu[i].num);
printf("请输入第%d个学生的成绩:",i+1);
scanf("%d",&stu[i].fenshu);
sum+=stu[i].fenshu;//求总分
}
printf("高于平均分的学生信息: ");
for(i=0;i<20;i++)
{
if(stu[i].fenshu>sum/20.0)
{
printf("学号:%s,成绩:%d ",stu[i].num,stu[i].fenshu);
}
}
}
Ⅶ 定义一个类,输入若干学生的学号、姓名和成绩,然后显示这些数据并计算出平均分。并设计程序测试该功能
#include<iostream.h>
#include<string.h>
#define N 10
class student
{
private:
char sno[20];
char name[10];
int score[6];
public:
void setinfo();
void showinfo();
void average();
};
void student::setinfo()
{
cin>>sno>>name>>score[0]>>score[1]>>score[2]>>score[3]>>score[4]>>score[5];
}
void student:: showinfo()
{
cout<<sno<<endl<<name<<endl<<score[0]<<endl<<score[1]<<endl<<score[2]<<endl<<score[3]<<endl<<score[4]<<endl<<score[5]<<endl;
}
void student::average()
{
double avg,sum=0.0;
for(int i=0;i<6;i++)
{
sum+=score[i];
}
avg=sum/6.0;
cout<<avg<<endl;
}
void main()
{
student *pstu=new student[N];
for(int i=0;i<N;i++)
{
cout<<"请输入第"<<i+1<<"名学生的学号、姓名、各科成绩(6门)"<<endl;
pstu[i].setinfo();}
for(i=0;i<N;i++)
{ cout<<"第"<<i+1<<"名学生信息:"<<endl;
pstu[i].showinfo();
}
for(i=0;i<N;i++)
{
cout<<"第"<<i+1<<"名学生平均成绩:"<<endl;
pstu[i].average();
}
}
Ⅷ 编写c程序,要求用户不断的输入学生的学号和考试成绩,直到学号为-1为结束,程序自动输出最高分,最低分。
#include <stdio.h>
typedef struct student
{
int no;
int score;
}student;
int main()
{
student stu[100], maxstu, minstu;
int i = 0;
while (scanf("%d%d", &stu[i].no, &stu[i].score) && stu[i].no != -1)
{
if (i == 0)
{
maxstu = stu[i];
minstu = stu[i];
}
else
{
if (maxstu.score < stu[i].score)
{
maxstu = stu[i];
}
if (minstu.score > stu[i].score)
{
minstu = stu[i];
}
}
i++;
}
printf("max student : no : %d score : %d\n", maxstu.no, maxstu.score);
printf("min student : no : %d score : %d\n", minstu.no, minstu.score);
return 0;
}
Ⅸ 2、 从键盘上输入一个学生的学号和考试成绩,然后输出该学生的学号和考试成绩,并根据成绩按下面的规定输
Private Sub Command1_Click()
Dim s$, a$, mark!
s = Text1.Text
mark = Val(Text2.Text)
Select Case mark
Case Is < 40
a = "fail"
Case Is < 50
a = "poor"
Case Is < 60
a = "fair"
Case Is < 80
a = "good"
Case 80 To 100
a = "very good"
End Select
Print "学号:" & s & vbCrLf & "成绩评定回为答" & a
End Sub
Ⅹ 从键盘上输入一个学生的学号和考试成绩,然后输出该学生的学号和考试成绩,并根据(
好的,没问题,把邮箱留下