| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 550 人关注过本帖
标题:麻烦大家了,谢谢
只看楼主 加入收藏
guodong661
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-2-15
收藏
 问题点数:0 回复次数:3 
麻烦大家了,谢谢

#include<iostream>
#include<cstring>
class student
{private:
std::string sname;
int grade;
public:
student():sname(0),grade(0){}
student(std::string name,int g=0)
{sname=name;
grade=g;
}
student(student &stu)
{sname=stu.getSname();
grade=stu.getGrade();
}//拷贝构造函数
std::string& getSname()
{return sname;}
int getGrade()
{return grade;}
student& operator=(student &stu)
{sname=stu.getSname();
grade=stu.getGrade();
return stu;
}
bool operator>(const student&);
bool operator<(const student&);
bool operator==(const student&);
bool operator!=(const student&);
void setGrade(int g)
{grade=g;}
void display();
void GradeTransition();//用于百分制到5分制的转换
~student(){}
};

bool student::operator>(const student &stu)
{if(this.grate>stu.getGrade())//当THIS对象的成绩大于STU的成绩时
{std::cout<<sname<<"成绩大于"<<stu.getSname();
return true;
}
else
{std::cout<<sname<<"成绩不大于"<<stu.getSname();
return false;}
}

bool student::operator<(const student &stu)
{if(this.grade<stu.getGrade())
{std::cout<<this.sname<<"成绩小于"<<stu.getSname();
return true;
}
else
{std::cout<<this.sname<<"成绩不小于"<<stu.getSname();
return false;
}
}

bool student::operator==(const student &stu)
{if(this.grade==getGrade())
{std::cout<<this.sname<<"成绩等于"<<stu.getSname();
return true;
}
else
{std::cout<<this.sname<<"成绩不等于"<<stu.getSname();
return false;
}

bool student::operator!=(const student &stu)
{if(this.grade!=stu.getGrade())
{std::cout<<this.sname<<"成绩不等于"<<stu.getSname();
return true;
}
else
return false;
}

void student::display()
{std::cout<<"姓名:"<<this.sname<<std::endl;
std::cout<<"成绩:"<<grade<<std::endl;
}

void student::GradeTransition()
{if(grate<=100&&grate>89)
{display();
std::cout<<"五分制成绩为:"<<'A'<<std::endl;
}
else if(grate>79)
{{display();
std::cout<<"五分制成绩为:"<<'B'<<std::endl;
}
else if(grate>69)
{{display();
std::cout<<"五分制成绩为:"<<'C'<<std::endl;
}
else if(grate>59)
{{display();
std::cout<<"五分制成绩为:"<<'D'<<std::endl;
}
else
{display();
std::cout<<"五分制成绩为:"<<'E'<<std::endl;
}
}

int main()
{
student stu1(wang,80)
stu1.display();
stu1.GradeTransition();
student stu2(stu1);
stu2.display();
stu2.GradeTransition();
stu1.setGrade(59);
stu1.display();
stu1.GradeTransition();
stu2.display();
stu2.GradeTransition();


}



搞了一个下午都没搞好 希望能得到高手的帮助 谢谢

搜索更多相关主题的帖子: 麻烦 
2006-03-05 16:27
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

class student
{
private:
string sname;
int grade;
public:
student():sname(0),grade(0){}
student(string name,int g=0)
{
sname=name;
grade=g;
}
student(const student & stu)
{
sname=stu.sname;
grade=stu.grade;
}//¿½±´¹¹Ô캯Êý
string & getSname()
{
return sname;
}
int getGrade(){return grade;}
student & operator=(const student & stu)
{
sname=stu.sname;
grade=stu.grade;
return *this;
}
bool operator>(const student &);
bool operator<(const student &);
bool operator==(const student &);
bool operator!=(const student &);
void setGrade(int g){grade=g;}
void display();
void GradeTransition();//ÓÃÓÚ°Ù·ÖÖƵ½5·ÖÖƵÄת»»
~student(){}
};

bool student::operator>(const student & stu)
{
if(grade>stu.grade)//µ±THIS¶ÔÏóµÄ³É¼¨´óÓÚSTUµÄ³É¼¨Ê±
{
cout<<sname<<\"³É¼¨´óÓÚ\"<<stu.sname;
return true;
}
else
{
cout<<sname<<\"³É¼¨²»´óÓÚ\"<<stu.sname;
return false;
}
}

bool student::operator<(const student & stu)
{
if(grade<stu.grade)
{
cout<<sname<<\"³É¼¨Ð¡ÓÚ\"<<stu.sname;
return true;
}
else
{
cout<<sname<<\"³É¼¨²»Ð¡ÓÚ\"<<stu.sname;
return false;
}
}

bool student::operator==(const student & stu)
{
if(grade==stu.grade)
{
cout<<sname<<\"³É¼¨µÈÓÚ\"<<stu.sname;
return true;
}
else
{
cout<<sname<<\"³É¼¨²»µÈÓÚ\"<<stu.sname;
return false;
}
}

bool student::operator!=(const student & stu)
{
if(grade!=stu.grade)
{
cout<<sname<<\"³É¼¨²»µÈÓÚ\"<<stu.sname;
return true;
}
else
return false;
}

void student::display()
{
cout<<\"ÐÕÃû£º\"<<sname<<endl;
cout<<\"³É¼¨£º\"<<grade<<endl;
}

void student::GradeTransition()
{
display();
if(grade<=100 && grade>89)
{
cout<<\"Îå·ÖÖƳɼ¨Îª£º\"<<'A'<<endl;
}
else if(grade>79)
{
cout<<\"Îå·ÖÖƳɼ¨Îª£º\"<<'B'<<endl;
}
else if(grade>69)
{
cout<<\"Îå·ÖÖƳɼ¨Îª£º\"<<'C'<<endl;
}
else if(grade>59)
{
cout<<\"Îå·ÖÖƳɼ¨Îª£º\"<<'D'<<endl;
}
else
{
cout<<\"Îå·ÖÖƳɼ¨Îª£º\"<<'E'<<endl;
}
}

int main()
{
student stu1(\"wang\",80);
stu1.display();
stu1.GradeTransition();
student stu2(stu1);
stu2.display();
stu2.GradeTransition();
stu1.setGrade(59);
stu1.display();
stu1.GradeTransition();
stu2.display();
stu2.GradeTransition();

system(\"pause\");
return 0;
}



自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-03-05 19:06
leileiguo
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-3-5
收藏
得分:0 
你这个程序是要干吗的啊
2006-03-05 20:57
guodong661
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-2-15
收藏
得分:0 
百分制成绩转换为5分制成绩

2006-03-09 02:26
快速回复:麻烦大家了,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029276 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved