64,675
社区成员
发帖
与我相关
我的任务
分享
2.
#include <iostream>
#include <string>
using namespace std;
class Person
{
private:
string Number;
string Name;
public:
Person(string Num="",string Nam=""):Number(Num),Name(Nam){}
virtual ~Person(){}
public:
virtual void Input()
{
cout<<"Please input the number:";
cin>>Number;
cout<<"Please input the name :";
cin>>Name;
}
virtual void Output()
{
cout<<"The number is:"<<Number<<endl;
cout<<"The name is:"<<Name<<endl;
}
};
class Student:public Person
{
private:
string Grade;
float Score;
public:
Student(string Gra="",float Sco=0.0):Grade(Gra),Score(Sco){}
~Student(){}
public:
void Input()
{
Person::Input();
cout<<"Please input the grade :";
cin>>Grade;
cout<<"Please input the score :";
cin>>Score;
}
void Output()
{
Person::Output();
cout<<"The grade is:"<<Grade<<endl;
cout<<"The score is:"<<Score<<endl;
}
};
int main()
{
Student stu;
stu.Input();
stu.Output();
return 0;
}
3.
#include <iostream>
using namespace std;
static int all_number=0;
class ShenStock
{
private:
int General;
int ST;
int PT;
public:
ShenStock(int ge=0,int st=0,int pt=0):General(ge),ST(st),PT(pt){}
friend int Total(ShenStock &s)
{
return (s.General+s.PT+s.ST);
}
friend static int count(ShenStock &s)
{
all_number+=Total(s);
return all_number;
}
};
class ShangStock
{
private:
int General;
int ST;
int PT;
public:
ShangStock(int ge=0,int st=0,int pt=0):General(ge),ST(st),PT(pt){}
friend int Total(ShangStock &s)
{
return (s.General+s.PT+s.ST);
}
friend static int count(ShangStock &s)
{
all_number+=Total(s);
return all_number;
}
};
int main()
{
ShenStock she(2,5,4);
cout<<"ShenStock Total:"<<Total(she)<<endl;
ShangStock sha(4,3,6);
cout<<"ShangStock Total:"<<Total(sha)<<endl;
count(she);
cout<<"All stock :"<<count(sha)<<endl;
return 0;
}
#include "stdafx.h"
#include <iostream>
using namespace std;
class Income
{
private:
float NuleadPrice,LeadPrice;
float TotalPrice;
float NuleadAmount,LeadAmount;
public:
Income(float NulP=17.00,float LeaP=16.00,float NulA=0.0,float LeaA=0.0,float TotP=0.0):
NuleadPrice(NulP),LeadPrice(LeaP),NuleadAmount(NulA),LeadAmount(LeaA),TotalPrice(TotP){}
public:
float GetTotalPrice()
{
return TotalPrice=NuleadPrice*NuleadAmount+LeadPrice*LeadAmount;
}
void PrintTotalPrice()
{
cout<<"Total Price:"<<TotalPrice<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
const float Nul_price=17.00,Lead_price=16.00;
float Nul_amount,Lead_amount;
cout<<"Please input nulead amount:";
cin>>Nul_amount;
cout<<"Please input lead amount:";
cin>>Lead_amount;
Income Inc(Nul_price,Lead_price,Nul_amount,Lead_amount);
Inc.GetTotalPrice();
Inc.PrintTotalPrice();
return 0;
}