輸入n個學生的學號成績
『壹』 編寫一個程序,輸入n個學生的學號,姓名,3門課程的成績,求出總分最高的學生並輸出該學生的所有信息,
#include "stdio.h"
#include "string.h"
#define NULL 0
typedef struct node
{long num;
char name[4];
float eng,math,com,total,ave;
struct node *next;
}LNode,*LinkedList;
LinkedList LinkedListCreat(LinkedList L )
{ LinkedList L,p,r,s,q;
int x,flag=-1;
float e,m,c;
printf("Please enter student numbers, input of -1 End \n");
scanf("%ld",&x);
while (x!=flag)
{ q=L;s=q->next;
while(s!=NULL&&s->num!=x)
{q=s; s=s->next;}
if(s==NULL)
{
p=(LinkedList)malloc(sizeof(LNode));
printf("Input student's name:");
scanf("%s\n",p->name);
printf("Input student's english:");
scanf("%f\n",&e);
printf("Input student's mathe:");
scanf("%f\n",&m);
printf("Input student's computer:");
scanf("%f\n",&c);
p->num=x;
p->eng=e;
p->math=m;
p->com=c;
p->total=(e+m+c);
p->ave=p->total/3.0;
if(L->next==NULL)
{ r=L;
r->next=p;
r=p;
r->next=NULL;
}
else
{q=L;s=q->next;
while(s!=NULL&&s->total>p->total)
{q=s; s=s->next;}
p->next=q->next; q->next=p;}
}
else
printf("have the same num,Resume load!\n ");
printf("Please enter student numbers, input of -1 End \n");
scanf("%ld",&x);
}
return L;
}
void print(LinkedList L) /*輸出鏈表中的結點*/
{LinkedList p;
p=L->next;
printf("num\tname\tEnglish\t\tmathe\tcomputer\ttotal\tave\n");
while(p!=NULL)
{
printf("%ld\t%s\t%.2f\t\t%.2f\t%.2f\t\t%.2f\t%.2f\t\n",p->num,p->name,p->eng,p->math,p->com,p->total,p->ave);
p=p->next;
}
}
main( )
{LinkedList L;
L=(LinkedList)malloc(sizeof(LNode));
L->next=NULL;
L=LinkedListCreat( L);
print(L);
}
『貳』 編寫一個程序,輸入N個學生數據,包括學號、姓名、C++成績,要求輸出這些學生的數據、平均分與成績等級。
#include<bits/stdc++.h>
using namespace std;
class Student
{
private:
int no;
char name[10];
int deg;
static int sum;
static int num;
public:
void setdata(int n,char na[],int d)
{
no=n;
strcpy(name,na);
deg=d;
sum+=d;
num++;
}
static double avg()
{
return sum/num;
}
void disp()
{
cout<<no<<name<<deg<<endl;
}
};
int Student::sum=0;
int Student::num=0;
int main()
{
int n;
cin>>n;
Student stu1,stu2;
stu1.setdata(201,"s",55);
stu2.setdata(203,"sss",88);
stu1.disp();
stu2.disp();
int s = Student::avg();
cout<<s<<endl;
}
(2)輸入n個學生的學號成績擴展閱讀
#include <stdio.h>
int main()
{
int x,y;
printf("請輸入x:");
scanf("%d",&x);
if(x>-5 && x<0)
y = x;
else if(x==0)
y = x-1;
else if(x>0 && x<10)
『叄』 編寫一個程序,輸入n個學生的學號,姓民,3門課程的成績,求出總分最高的學生並輸出該學生的所有信息
你的錯誤是比不知道C語言的索引是從0開始的么,而不是1,
#include<stdio.h>
#definen3
structSTUDENT
{
charname[20];
charnumber[10];
intscore[3];
intsum;
};
main()
{
inti=0,j=0,max=0,maxi=0;
structSTUDENTstu[n];
for(i=0;i<n;i++)
{
printf("Pleaseinputstudent%d'sinformation ",i+1);
printf("Number:");
scanf("%s",stu[i].number);
printf("Name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{
printf("Score[%d]:",j);
scanf("%d",&stu[i].score[j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{stu[i].sum+=stu[i].score[j];}
if(max<stu[i].sum)
{
max=stu[i].sum;
maxi=i;
}
}
printf("Thehigheststudentisstudent%d:%s%s%d%d%d ",maxi,stu[maxi].number,stu[maxi].name,stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2]);
}
『肆』 編寫一個程序,輸入N個學生的成績,輸出高於平均成績的學生的學號和成績.
VB:
private command1_click()
dim a(10) as single
for i=1 to 10
a(i)=inputbox("輸入第"+i+"個數:內容")
sum=sum+a(i)
next i
sum=sum/10
for i=1 to 10
if i>sum then print a(i);
next i
end sub
『伍』 編寫一個程序,輸入N個學生的成績,輸出高於平均成績的學生的學號和成績,其中學號和
這個是我以前無聊的時候編的,雖然和你的題目有點不一樣,但是基本的功能都有,你拿去參考一下吧!
由於編的時候還沒有學結構體,所以這里沒有使用結構體……
#define N 6
/*共有6個同學,在這里根據實際學生人數修改學生數*/
#define M 4
/*有3門課*/
main()
{int score[N][M],i,j,sum[N]={0};
float average[M],sum1,sum2=0.0;
for(i=0;i<N;i++)
score[i][0]=i+1; /*編學號*/
for(j=0;j<N;j++)
{printf("Please input num %d's score!\n",j+1);
for(i=1;i<M;i++)
scanf("%d",&score[j][i]); /*根據學號分別輸入各位學生各科的成績 */
}
for(i=0;i<N;i++)
for(j=1;j<M;j++)
sum[i]+=score[i][j]; /*求每個人的成績總分*/
for(i=1;i<M;i++)
{sum1=0.0;
for(j=0;j<N;j++)
{sum1+=score[j][i];
sum2+=sum[j];
}
average[i-1]=sum1/N;
average[M-1]=sum2/N/(M-1); /*求每門課及總分的平均分 */
}
printf("Num\tChinese\tEnglish\tMaths\tSum\n");
for(i=0;i<N;i++)
{for(j=0;j<M;j++)
printf("%d\t",score[i][j]);
printf("%d\n",sum[i]);
}
printf("\n");
printf("Average:");
for(i=0;i<M;i++)
printf("%.3f\t",average[i]);
getch();
}
『陸』 c++讀入n名學生的姓名、學號、成績,分別輸出成績最高和成績最低學生的姓名和學號。
我看了一下你的代碼,發現你的思路是:分數在0-100之間且不存在兩個相同的分數,於是,用相對應得分數儲存數據,而且用一個judge為真假來判斷該位置是否被佔用。尋找最大的方式是從100往下看,當遇到第一個judge為真的時候就是最大,最小的反之即可。
然後,我發現你的錯誤是:judge[j]=1,應該改為:judge[j]==1。
下面是更加簡單的思路和方法(可能存在些許失誤):
#include <iostream>
using namespace std;
int main(){
int number;
string maxName,maxID,maxScore;
string minName,maxID,minScore;
string tempName,tempID,tempScore;
cin >> number;
for(int i=0;i<number;i++){
cin >> tempName >> tempID >> tempScore;
if(i == 0){
maxName=tempName;
maxID=tempID;
maxScore=tempScore;
minName=tempName;
minID=tempID;
minScore=tempScore;
}else if(tempScore >maxScore){
maxName=tempName;
maxID=tempID;
maxScore=tempScore;
}else if(minScore > tempScore){
minName=tempName;
minID=tempID;
minScore=tempScore;
}
}
cout << maxName << " " << maxID << endl;
cout << minName << " " << minID << endl;
return 0;
}
『柒』 用C語言編寫一個程序,輸入N個學生的學號和成績,求平均成績,並輸出其中最高分和最低分學生學號和成績
#include<stdio.h>
#defineN5
structStu{
intid;
doublescore;
};
voidsortScore(Stus[N]){
inti;
intmin=0,max=0;
for(i=1;i<N;i++){
if(s[i].score>s[max].score)max=i;
if(s[i].score<s[min].score)min=i;
}
printf("%d%.2lf ",s[max].id,s[max].score);
printf("%d%.2lf ",s[min].id,s[min].score);
}
intmain(){
Stus[N];
inti;
doubleans=0;
for(i=0;i<N;i++){
scanf("%d%lf",&s[i].id,&s[i].score);
ans+=s[i].score;
}
printf("%.2lf ",ans/N);
sortScore(s);
}
『捌』 修改下列程序,使得程序的功能是輸入n個學生的學號、成績,計算其平均成績 求大神幫我修改
#include<stdio.h>
#include<stdlib.h>
structstudent
{
charnum[20];
doublescore;
}stu[10];
voidinput(structstudent*p,intn)
{
inti;
for(i=0;i<n;i++)
{
printf("請輸入第%d個學生學號: ",i+1);
scanf("%s",p[i].num);
printf("請輸入第%d個學生成績: ",i+1);
scanf("%lf",&p[i].score);
}
}
doubleaverage(structstudent*p,intn)
{
inti;
doublesum=0;
for(i=0;i<n;i++)
sum+=p[i].score;
returnsum/n;
}
intmain()
{
structstudent*p=stu;
intn;
printf("請收輸入學生人數,但不能超過10人:");
scanf("%d",&n);
input(p,n);
printf("%d個學生的平均成績為:%10.2f ",n,average(p,n));
system("pause");
return0;
}
『玖』 存入N個同學的成績表(學號、姓名、成績),輸入學號或姓名,查找其成績。
//ok了,不過我不是姐姐。我只是貼錯頭像,不知怎麼弄成男的。暈。。
#include<stdio.h>
#include<string.h>
#define N 100 //當學生數目>N時,修改這里的值。
struct Student
{
char xuehao[100];
char name[100];
int grade;
};
Student stu[N];
void main()
{
char ans[100];
int choose;
int n;
int i;
printf("請輸入學生的人數:");
scanf("%d",&n);
printf("請分別輸入學生的學號,姓名,成績\n");
for(i=0;i<n;i++)
scanf("%s%s%d",&stu[i].xuehao,&stu[i].name,&stu[i].grade);
do
{
printf("請選擇你要查詢的方式:\n1.按學號\n2.按姓名\n0.退出\n");
scanf("%d",&choose);
if(choose==1)
{
printf("請輸入你要查詢的學號:\n");
scanf("%s",&ans);
for(i=0;i<n;i++)
{
if(strcmp(ans,stu[i].xuehao)==0)
{
printf("姓名:%s\n學號:%s\n成績:%d\n",stu[i].name,stu[i].xuehao,stu[i].grade);
break;
}
}
if(i==n) printf("無此學號\n");
}
else if(choose==2)
{
printf("請輸入你要查詢的姓名:\n");
scanf("%s",&ans);
for(i=0;i<n;i++)
{
if(strcmp(ans,stu[i].name)==0)
{
printf("姓名:%s\n學號:%s\n成績:%d\n",stu[i].name,stu[i].xuehao,stu[i].grade);
break;
}
}
if(i==n) printf("無此姓名\n");
}
else if(choose==0)
{
break;
}
else
{
printf("輸入無效,請重新輸入\n");
}
}while(choose!=0);
}
『拾』 編寫一個程序,輸入N個學生數據,包括學號,姓名,成績,要求輸出這些學生數據並計算平均分,設計一
#include <iostream.h>
#include <stdlib.h>
class student
{
public:
int no;
char *name;
int deg;
student();
~();
void display();
};
static int sum,num=3;
static int avg(int sum);
void main()
{
int aver;
student stu[3];
stu[0].no=1;
stu[0].name="li";
stu[0].deg=89;
stu[1].no=2;
stu[1].name="chen";
stu[1].deg=78;
stu[2].no=3;
stu[2].name="zheng";
stu[2].deg=94;
for(int i=0;i<3;i++)
{
stu[i].display();
sum+=stu[i].deg;
}
cout<<"the sum is:"<<sum<<endl;
aver=avg(sum);
cout<<"the average is:"<<aver<<endl;
}
student::student()
{
no=0;
name=(char*)malloc(sizeof(char)*8);
deg=0;
}
student::~student()
{
free(name);
}
void student::display()
{
cout<<no<<"\t"<<name<<"\t"<<deg<<endl;
}
static int avg(int sum)
{
int aver;
aver=sum/num;
return aver;
}