>即時新聞-熱門

2008年8月25日星期一

類別 - 最大值

#include<iostream>

using namespace std;

class basedata {
private:
char no[6];     
char name[20];  
int math;
int china;  
    int english; 
int scoresum(void);
float scoreavg(void);
int scoremax(void);
public:
void inputbasedata();
void showbasedata();
};
void basedata::inputbasedata(void)  

cout << "****************************" << endl;
         cout << "學號:" ;
cin >> no;
cout <<endl<< "姓名:";
cin >> name ;
            cout <<endl<< "數學:";
cin >> math;
cout <<endl<< "國文:";
cin >> china;
cout <<endl<< "英文:";
cin >> english;



void basedata::showbasedata(void)  
 { 
int sum;
   float avg;
   int mymax;
   sum=scoresum();
   avg=scoreavg();
   mymax=scoremax();


cout << "***************************" << endl;

cout << "學號:" << no << endl;
cout << "姓名:" << name << endl;
cout << "數學:" << math << endl;
cout << "國文:" << china << endl;
cout << "英文:" << english << endl;
cout << "***************************" << endl;
              cout << "總分:" << sum<< endl;
         cout << "平均:" << avg << endl;
cout << "最大值:" << mymax << endl;

int basedata::scoresum()  
{   
int my_sum;
   my_sum=math+china+english;
   return my_sum;



float basedata::scoreavg()  
{   
float my_avg;
   my_avg=(math+china+english)/3;
   return my_avg;



int basedata::scoremax()  
{   
int my_max;
if (math > china){
if (math >english){
   my_max=math;

else{
my_max=english;


else{
if (china >english){
   my_max=china;

else{
my_max=english;



  
   return my_max;



void main()

basedata a[4];
int i;
cout<<"請輸入資料"<<endl;
for(i=0;i<4;i++){

      a[i].inputbasedata();

cout<<"資料輸出"<<endl;
for(i=0;i<4;i++){
a[i].showbasedata();

0 评论:

 
妹咕數位學園歡迎網友們來信指教 妹咕信箱