導航:首頁 > 源碼編譯 > 編譯程序輸入學生的三個課程成績

編譯程序輸入學生的三個課程成績

發布時間:2024-09-23 11:11:32

㈠ 設計一個學生類CStudent,包括姓名和三門課程成績,利用重載運算符「+」將所有學生C++

如下:

#include <iostream>

#include <cstring>

#include<IOMANIP>

using namespace std;

class student

{

private:

char a[20]; //不能在類定義中對非static const型變數賦值

int x ,y ,z;

int cnt; //計數器,存放成績對應的人數。默認為1個學生的成績。

public :

student():cnt(1){

a[0]='';

x=y=z=0;

}

student (char *b,int m,int k,int t):cnt(1)

{

strcpy(a,b); //字元串賦值

x=m;

y=k;

z=t;

}

student operator +(const student& s);//const 引用,提高效率

void print()

{

cout<<"course 1#,ave score:="<<fixed<<setprecision(2)<<(float) x/cnt<<endl;

cout<<"course 2#,ave score:="<<fixed<<setprecision(2)<<(float) y/cnt<<endl;

cout<<"course 3#,ave score:="<<fixed<<setprecision(2)<<(float) z/cnt<<endl;

}

};

student student:: operator +(const student& s)

{

student b;

b.x=x+s.x;

b.y=y+s.y;

b.z=z+s.z。

C語言是一門面向過程的計算機編程語言,與C++、Java等面向對象編程語言有所不同。C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、僅產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

C語言描述問題比匯編語言迅速,工作量小、可讀性好,易於調試、修改和移植,而代碼質量與匯編語言相當。C語言一般只比匯編語言代碼生成的目標程序效率低10%~20%。因此,C語言可以編寫系統軟體。

二十世紀八十年代,美國國家標准局為了避免各開發廠商用的C語言語法產生差異,給C語言制定了一套完整的美國國家標准語法,稱為ANSI C。

作為C語言最初的標准。2011年12月8日,國際標准化組織(ISO)和國際電工委員會(IEC)發布的C11標準是C語言的第三個官方標准,也是C語言的最新標准,該標准更好的支持了漢字函數名和漢字標識符,一定程度上實現了漢字編程。

C語言編譯器普遍存在於各種不同的操作系統中,例如Microsoft Windows, Mac OS X, Linux, Unix等。C語言的設計影響了眾多後來的編程語言,例如C++、Objective-C、Java、C#等。

㈡ C語言 編寫程序處理10個學生的信息,每個學生的信息包括:學號、姓名、三門成績。平均分 前三名

#include <stdio.h>
#define NUM 10
#define SHOW 3

struct student {
int id; //學號
char name[20]; //名字
float score[3]; //3門成績
float average; //平均分
}info[NUM];

void getdata() //接受學生數據
{
int i;

for(i=0; i<NUM; i++)
{
printf("please input the %d student infomation like:\n",i+1);
printf("id name score(1) score(2) score(3)\n");
scanf("%d %s %f %f %f",&info[i].id,info[i].name,&info[i].score[0],&info[i].score[1],&info[i].score[2]);
info[i].average = (info[i].score[0] + info[i].score[1] + info[i].score[2])/3.0;
}
return ;
}

void showlist() //輸出成績表
{
int i;

printf("the student information list:\n");
printf("id\tname\tscore(1)\tscore(2)\tscore(3)\taverage\n");
for(i=0; i<NUM; i++)
{
printf("%d\t%s\t%.2f",info[i].id,info[i].name,info[i].score[0]);
printf("\t\t%.2f\t\t%.2f\t\t%.2f\n",info[i].score[1],info[i].score[2],info[i].average);
}

}

void showtop() //平均分前3名的名字和平均分
{
int i,j;
struct student top;

for(i=0; i<NUM; i++)
{
for(j=0; j<(NUM-i); j++)
{
if(info[j].average > info[j+1].average)
{
top = info[j];
info[j] = info[j+1];
info[j+1] = top;
}
}
}

printf("the top three average is:\n");
printf("name\taverage\n");
for(i=NUM; i>NUM-SHOW; i--)
{
printf("%s\t%.2f\n",info[i].name,info[i].average);
}

return;
}

int main()
{
getdata();
showlist();
showtop();
return 0;
}

看到題目現寫的,完全按照題目的意思,編譯通過,請採納! 另外可以通過更改宏NUM的值修改學生的個數,更改宏SHOW的值修改顯示最高平均分的人數。

閱讀全文

與編譯程序輸入學生的三個課程成績相關的資料

熱點內容
Vs中的內部編譯器錯誤 瀏覽:313
江蘇銀行明細解壓密碼怎麼查詢 瀏覽:452
python3百度關鍵字圖片 瀏覽:241
程序員到底是鐵飯碗 瀏覽:337
以家人之名哪個app 瀏覽:791
福昕加密伺服器 瀏覽:692
計算機科學和程序員 瀏覽:250
劇集網app哪個好用 瀏覽:70
程序員開店經驗分享 瀏覽:635
如何遠程上傳文件到linux伺服器 瀏覽:972
易語言編譯器代碼 瀏覽:244
文件夾漂亮又簡單 瀏覽:975
不知網站的伺服器是哪的怎麼登錄 瀏覽:3
android中心點坐標 瀏覽:279
采耳視頻解壓耳內鏡 瀏覽:69
哪個app搜題能整頁的搜 瀏覽:970
javaexcel對象 瀏覽:829
做生鮮配送員選擇哪個app好 瀏覽:785
編譯程序輸入學生的三個課程成績 瀏覽:264
哪裡下載國外新聞app 瀏覽:882