用class写程式的问题
我现在要写一个程式, 要求输入3个学生的姓和名(分开来输入姓,名), 然后输入这3个人的3个成绩, 然后算出平均分, 输出 是三个人的名字, 三个人的成绩, 三个人的平均分数, 还要输出谁的分数最高, 谁的最低, 谁的在中间输出应该像这样:
王 90, 90, 90, 平均:90 最高
李 80, 80, 80, 平均:80 中间
张 70, 70, 70, 平均:70 最低
但是前提一定要是用class来编写
这个程式我差不多写完了, 但是最后比谁高谁低的,我是先把他们的平均分按从小到大排了, 但是现在排列出了点问题,大家帮忙找一找我的错误。(在最下面)
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
class personType
{
public:
void print() const;
void printTwo() const;
void printThree() const;
void setNameOne (string first, string last);
void setScore (int one, int two, int three);
string getFirstNameOne() const;
string getLastNameOne() const;
int OnegetFirstScore() const;
int OnegetSecondScore() const;
int OnegetThirdScore() const;
string personTypeOne (string first="", string last="");
int personOneScore (int one, int two, int three);
double getaveOne();
void setNameTwo (string first_two, string last_two);
void setScoreTwo (int one_two, int two_two, int three_two);
string getFirstNameTwo() const;
string getLastNameTwo() const;
int TwogetFirstScore() const;
int TwogetSecondScore() const;
int TwogetThirdScore() const;
string personTypeTwo (string first_two="", string last_two="");
int personTwoScore (int one_two, int two_two, int three_two);
double getaveTwo();
void setNameThree (string first_three, string last_three);
void setScoreThree (int one_three, int two_three, int three_three);
string getFirstNameThree() const;
string getLastNameThree() const;
int ThreegetFirstScore() const;
int ThreegetSecondScore() const;
int ThreegetThirdScore() const;
string personTypeThree (string first_three="", string last_three="");
int personThreeScore (int one_three, int two_three, int three_three);
double getaveThree();
private:
string OnefirstName;
string OnelastName;
string TwofirstName;
string TwolastName;
string ThreefirstName;
string ThreelastName;
int firstScore;
int secondScore;
int thirdScore;
int twofirstScore;
int twosecondScore;
int twothirdScore;
int threefirstScore;
int threesecondScore;
int threethirdScore;
};
void personType::print() const
{
cout<<OnefirstName<<""<<OnelastName;
}
void personType::printTwo() const
{
cout<<TwofirstName<<""<<TwolastName;
}
void personType::printThree() const
{
cout<<ThreefirstName<<""<<ThreelastName;
}
void personType::setNameOne(string first, string last)
{
OnefirstName=first;
OnelastName=last;
}
void personType::setScore (int one, int two, int three)
{
firstScore=one;
secondScore=two;
thirdScore=three;
}
string personType::getFirstNameOne() const
{
return OnefirstName;
}
string personType::getLastNameOne() const
{
return OnelastName;
}
int personType::OnegetFirstScore() const
{
return firstScore;
}
int personType::OnegetSecondScore() const
{
return secondScore;
}
int personType::OnegetThirdScore() const
{
return thirdScore;
}
string personType::personTypeOne(string first, string last)
{
OnefirstName=first;
OnelastName=last;
}
int personType::personOneScore (int one, int two, int three)
{
firstScore=one;
secondScore=two;
thirdScore=three;
}
double personType::getaveOne()
{
return (firstScore+secondScore+thirdScore)/3;
}
void personType::setNameTwo(string first_two, string last_two)
{
TwofirstName=first_two;
TwolastName=last_two;
}
void personType::setScoreTwo (int one_two, int two_two, int three_two)
{
twofirstScore=one_two;
twosecondScore=two_two;
twothirdScore=three_two;
}
string personType::getFirstNameTwo() const
{
return TwofirstName;
}
string personType::getLastNameTwo() const
{
return TwolastName;
}
int personType::TwogetFirstScore() const
{
return twofirstScore;
}
int personType::TwogetSecondScore() const
{
return twosecondScore;
}
int personType::TwogetThirdScore() const
{
return twothirdScore;
}
string personType::personTypeTwo(string first_two, string last_two)
{
TwofirstName=first_two;
TwolastName=last_two;
}
int personType::personTwoScore (int one_two, int two_two, int three_two)
{
twofirstScore=one_two;
twosecondScore=two_two;
twothirdScore=three_two;
}
double personType::getaveTwo()
{
return (twofirstScore+twosecondScore+twothirdScore)/3;
}
void personType::setNameThree(string first_three, string last_three)
{
ThreefirstName=first_three;
ThreelastName=last_three;
}
void personType::setScoreThree (int one_three, int two_three, int three_three)
{
threefirstScore=one_three;
threesecondScore=two_three;
threethirdScore=three_three;
}
string personType::getFirstNameThree() const
{
return ThreefirstName;
}
string personType::getLastNameThree() const
{
return ThreelastName;
}
int personType::ThreegetFirstScore() const
{
return threefirstScore;
}
int personType::ThreegetSecondScore() const
{
return threesecondScore;
}
int personType::ThreegetThirdScore() const
{
return threethirdScore;
}
string personType::personTypeThree(string first_three, string last_three)
{
ThreefirstName=first_three;
ThreelastName=last_three;
}
int personType::personThreeScore (int one_three, int two_three, int three_three)
{
threefirstScore=one_three;
threesecondScore=two_three;
threethirdScore=three_three;
}
double personType::getaveThree()
{
return (threefirstScore+threesecondScore+threethirdScore)/3;
}
int main()
{
personType name;
string l, f, l_two, f_two, l_three, f_three;
int one, two, three, one_two, two_two, three_two, one_three, two_three;
int a[3], three_three, i, aterm, count=0;
cout<<"student #1.\n";
cout<<"input first name.\n";
cin>>f;
cout<<"input last name.\n";
cin>>l;
cout<<endl;
cout<<"enter 3 scores for student #1.\n";
cin>>one>>two>>three;
name.setNameOne(f, l);
name.setScore(one, two, three);
cout<<endl;
cout<<"student #2.\n";
cout<<"input first name.\n";
cin>>f_two;
cout<<"input last name.\n";
cin>>l_two;
cout<<endl;
cout<<"enter 3 scores for student #2.\n";
cin>>one_two>>two_two>>three_two;
name.setNameTwo(f_two, l_two);
name.setScoreTwo(one_two, two_two, three_two);
cout<<endl;
cout<<"student #3.\n";
cout<<"input first name.\n";
cin>>f_three;
cout<<"input last name.\n";
cin>>l_three;
cout<<endl;
cout<<"enter 3 scores for student #3.\n";
cin>>one_three>>two_three>>three_three;
name.setNameThree(f_three, l_three);
name.setScoreThree(one_three, two_three, three_three);
cout<<endl;
cout<<"------------------------------\n";
cout<<"the name for student #1 is:\n";
cout<<name.getLastNameOne()<<", "<<name.getFirstNameOne()<<endl;
cout<<"the 3 scores for student #1 is:\n";
cout<<name.OnegetFirstScore()<<", "<<name.OnegetSecondScore()<<", ";
cout<<name.OnegetThirdScore()<<endl;
cout<<"the average for student #1 is:\n";
cout<<name.getaveOne()<<endl;
cout<<endl;
cout<<"the name for student #2 is:\n";
cout<<name.getLastNameTwo()<<", "<<name.getFirstNameTwo()<<endl;
cout<<"the 3 scores for student #2 is:\n";
cout<<name.TwogetFirstScore()<<", "<<name.TwogetSecondScore()<<", ";
cout<<name.TwogetThirdScore()<<endl;
cout<<"the average for student #2 is:\n";
cout<<name.getaveTwo()<<endl;
cout<<endl;
cout<<"the name for student #3 is:\n";
cout<<name.getLastNameThree()<<", "<<name.getFirstNameThree()<<endl;
cout<<"the 3 scores for student #3 is:\n";
cout<<name.ThreegetFirstScore()<<", "<<name.ThreegetSecondScore()<<", ";
cout<<name.ThreegetThirdScore()<<endl;
cout<<"the average for student #3 is:\n";
cout<<name.getaveThree()<<endl;
cout<<endl;
a[0]=name.getaveOne();
a[1]=name.getaveTwo();
a[2]=name.getaveThree();
do //这里我排列了一下
{
if (a[i]>a[i+1])
{
aterm=a[i];
a[i]=a[i+1];
a[i+1]=aterm;
count=1;
i=1;
}
else if ((a[i]<=a[i+1]) && i<3)
{
i++;
count=1;
}
else
{
count=0;
}
}while (count==1);
for (i=0; i<3; i++) //这里我输出排列, 但是输出不正确(拜托大家找找毛病)
{
cout<<a[i]<<endl;
}
system("PAUSE");
return 0;
}
[[it] 本帖最后由 suckdog 于 2008-6-4 02:31 编辑 [/it]]