急急急!!!求C++高手帮忙!

ws274888829 2008-12-27 12:05:34
求C++高手帮忙帮忙编下以下程序,因为我刚开始学C++,以下这是测试题,本人感激不尽!!!
1、以面向对象的概念设计一个类,此类包含3个私有数据:nulead(无铅汽油)、lead(有铅汽油)以及total(当天总收入)。无铅汽油的价格是17元/公升,有铅汽油的价格是16元/公升。请以构造函数方式建立此值。试输入某天所加的汽油量,本程序将列出加油站当天的总收入。
2、编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数据操作类teacher的基类。
3、编写一个有关股票的程序,其中有两个类:一个是深圳类shen_stock,另一个是上海类shang_stock.类中有3个私有数据成员:普通股票个数general\ ST股票个数st和PT股票个数pt,每一个类分别有自己的友元函数来计算并显示深圳或上海的股票总数(3项之和).两个类共用一个count(),用来计算深圳和上海总共有多少股票并输出.
4、定义一个类stock,记录一支股票交易的基本信息,信息包括交易日序号(表示本月的第几个交易,用整数表示)\当日最高价\当日最低价\当日开盘价和当日收盘价.并定义一个对象数组存放连续5个交易日的股票信息.编写一个主函数,计算两个stock对象(前后两天)的当日收盘计算当日涨幅.(提示:用指针引用对象数组中的两个对象,在主函数中调用该函数计算从第2个交易日开始每天的当日涨幅.)
...全文
626 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ws274888829 2008-12-28
  • 打赏
  • 举报
回复
明白,明白!
arong1234 2008-12-28
  • 打赏
  • 举报
回复
老实说这不是在帮你,别人“帮”了你,你就永远学不会C++
这种帮忙从你说是害了你,从别人说是浪费时间
[Quote=引用 8 楼 ws274888829 的回复:]
帮助别人等于帮助自己,等待第4个答案!
[/Quote]
ws274888829 2008-12-28
  • 打赏
  • 举报
回复
帮助别人等于帮助自己,等待第4个答案!
josephwuxiaameng 2008-12-27
  • 打赏
  • 举报
回复
三楼写的还可以
楼主加油哦!

liubuweiright 2008-12-27
  • 打赏
  • 举报
回复
up
就呆在云上 2008-12-27
  • 打赏
  • 举报
回复

顶一下啦
哈哈
ws274888829 2008-12-27
  • 打赏
  • 举报
回复
谢谢阿猫 还有第4个了啊!!
急求第4个答案!
yangkunhenry 2008-12-27
  • 打赏
  • 举报
回复

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;
}

我总感觉自己写的类比较傻……
哪位大虾能把最后一个的代码晒一下?
PS:lz写好了也把代码贴下吧,大家都学习学习
wwwypy 2008-12-27
  • 打赏
  • 举报
回复
用c++编一点都不难。
yangkunhenry 2008-12-27
  • 打赏
  • 举报
回复

#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;
}

欢迎拍砖

64,675

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧