c++実験まとめ

7494 ワード

金曜日にc++模擬試験があることを考慮します.のまた崔さんが出した新しいテーマです.のだから、以前やった実験と学んだ重要な知識点や考え方をまとめてみましょう.Problem A:学生は大きさ//穴がない.実験のテスト用例が不完全で最初の答えはバグがあって直しても大丈夫だと思います.
#include 
#include
using namespace std;
class Student
{
public:
    string name;
    int age;
    Student()
    {
        name="";
        age=0;
    }
    int operator>(Student another)
    {
        if(age>another.age)
            return 1;
        else if(age==another.age)
        {
            int i=0;
            while(i!=name.size()||i!=another.name.size())
            {
                if(name[i]>another.name[i])
                    return 1;
                else if(name[i]==another.name[i])
                 i++;
                else
                    return 0;
            }
        }
    }
   friend ostream& operator<friend istream& operator>>(istream& is,Student& another);

};
ostream& operator<cout<" "<return os;
    }
    istream& operator>>(istream& is,Student& another)
    {
        cin>>another.name>>another.age;
        return is;
    }
int main()
{
    Student stu, max;
    while(cin>>stu)
    {
        if (stu > max)
            max = stu;
    }
    cout<return 0;
}

Problem B:学生のランキング:最大の穴は先生main関数がこっそり変えたことです.
#include 
#include
#include
#include
#include 
using namespace std;
class Student
{
private:
    string name;
    int age;
public:
    Student()
    {
        age=0;
        name="";

    }
   int operator>(Student another)
    {
        if(age>another.age)
            return 1;
        else if(age==another.age)
        {
            int i=0;
            while(i!=name.size()||i!=another.name.size())
            {
                if(name[i]>another.name[i])
                    return 1;
                else if(name[i]==another.name[i])
                 i++;
                else
                    return 0;
            }
        }
    }
    int operatorif(agereturn 1;
        else
            return 0;
    }
    friend istream &operator>>(istream& is,Student& stu);
    friend ostream &operator<class StudentGroup:public Student
{
public:
    vector V;
    void add(Student tmp)
    {
        V.push_back(tmp);
    }
    void srt()
    {
        vector::iterator iter1;
        vector::iterator iter2;
        Student tmp;
        for(iter1=V.begin();iter1!=V.end();iter1++)
        {
            for(iter2=V.begin();iter2!=V.end();iter2++)
            {
                if(*iter1void show()
    {
        vector::iterator iter1;
        for(iter1=V.begin();iter1!=V.end();iter1++)
        {
            cout<operator>>(istream& in,Student& s)
{
    in>>s.name;
    in>>s.age;
    return in;
}
ostream &operator<cout<" "<return os;
}
int main()
{
    Student stu, max;
    StudentGroup stuG;
    while(cin>>stu)
    {
        if (!(stu < max))
            max = stu;
        stuG.add(stu);
    }
    stuG.srt();
    stuG.show();
    cout<<"The max is "<return 0;
}

最後に1時間以上かけて2つの問題を作ったので、私も絶望しました.の