面向对象程序设计(C++)

面向对象程序设计(C++),第1张

#include <iostream>

#include <string>

using namespace std;

class CDog

{

int m_nAge;

float m_fWeight;

string m_strColor;

string m_strName;

public:

CDog(int Age, float Weight, string str1, string str2)

{

m_nAge = Age;

m_fWeight = Weight;

m_strColor = str1;

m_strName = str2;

}

CDog()

{

m_nAge = 2;

m_fWeight = 10;

m_strColor = "黑色";

m_strName = "旺才";

}

void show()

{

cout<<"狗名:"<<m_strName

<<"\n年龄:"<<m_nAge

<<"\n体重:"<<m_fWeight

<<"\n颜色:"<<m_strColor<<endl;

}

void Set(int Age, float Weight, string str1, string str2)

{

m_nAge = Age;

m_fWeight = Weight;

m_strColor = str1;

m_strName = str2;

}

~CDog()

{

}

};

int main()

{

CDog dog//(写参数);

// dogSet(写参数);

dogshow();

return 0;

}

不全是按照你的意思弄的,是我原来自己写着玩写的。 public class cStudy {

//构造函数,初始化学生信息

public cStudy(string _code,string _name,float _chinese,float _math, float _english)

{

Code=_code;

Name=_name;

Chinese=_chinese;

Math=_math;

English=_english;

}

public string Code; public string Name;

public float Chinese;

public float Math;

public float English;

float totalScore;

public float TotalScore

{

get

{

return Chinese + Math + English;

}

}

}

public class Cricle

{

public const double IP=314;

public static double Grith;

private double _r;

public double R

{

get { return _r; }

set

{

if (_r > 0)

{

_r = value;

}

}

}

public double getArea(double userR)

{

R = userR;

return IP R R;

}

public double getGrith(double userR)

{

R = userR;

return 2 IP R;

}

}

class salary

{

private:

double wage,subsidy,rent,waterfee,elecfee;

public:

salary(double wg=1000,ss=1000,rn=1000,wf=1000,ef=1000)

{

wage=wg;

subsidy=ss;

rent=rn;

watefree=wf;

elecfee=ef;

}

salary()

{

wage=0;

subsidy=0;

rent=0;

waterfee=0;

elecfee=0

}

//以下是set函数,设置各分项数据

void setwage(double wg)

{wage=wg;}

void setsubsidy(double ss)

{subsidy=ss;}

void setrent(double rn)

{rent=rn;}

void setwaterfee(double wf)

{waterfee=wf;}

void setelecfee(double ee)

{elecfee=ee;}

//以下是get函数,得到各分项数据

double getwage()

{return wage;}

double getsubsidy()

{return subsidy;}

double getrent()

{return rent;}

double getwaterfee()

{return waterfee;}

double

//////////以上你按照补齐吧

double realsalary()

{

double sum;

sum=wage+subsidy+rent+waterfee+elecfee;

return sum;

}

}

}

以上就是关于面向对象程序设计(C++)全部的内容,包括:面向对象程序设计(C++)、C# 面向对象程序设计、c++面向对象程序设计 急用请调试等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zz/9289869.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存