java类的成员函数_实际上使用我的类成员函数

我正在尝试用以下方式创建一个输入/输出的程序,注意我还没有完成所有的功能 . 我只需要一些关于如何开始的提示,因为我完全不知道该怎么做......任何提示/帮助都会如此受到赞赏 .

输入如下:

添加Alice

添加鲍勃

更新Alice笔记本电脑6000 2

输出Alice

更新Bob deskTop 18000 4

更新Bob tabLet 4600 3

输出Bob

添加查理

此输入的输出:

爱丽丝是卖家1 .

鲍勃是卖家2 .

爱丽丝售出2台笔记本电脑,售价为6000美元 .

爱丽丝:6000美元;卖了2个LapTops,0个DeskTops和0个平板电脑 .

鲍勃以18000美元的价格出售了4台台式电脑 .

鲍勃以4600美元的价格出售了3台平板电脑 .

鲍勃:22600美元;卖了0个LapTops,4个DeskTops和3个平板电脑 .

查理是卖家3 .

我真的不知道从哪里开始...我需要能够输入命令后跟成员函数参数的参数...但是真的不知道如何合并这个...这是我的第二个月在C中,请注意我真的不知道任何高级的东西 . 我对课程有所了解....

主要问题是如何实际使用这些......

其他重要信息:::: 1.添加 - 添加命令 . 如果具有该名称的卖方尚不存在且列表未满,则将具有给定名称(卖方名称)的卖方添加到列表的末尾 . 该名称将是一个连续的非空白字符序列 . 你的程序不需要检查这个 . 参见样本输出 .

输出 - 输出命令 . 输出销售的计算机的总 Value 以及为该销售商销售的每种计算机的总数 . 如果卖家不存在,请打印相应的消息 . 参见样本输出 .

更新 - 更新命令 . 使用给定的销售额和适当数量的计算机更新卖家 . 对于此命令:卖方名称指定销售人员的姓名; typeOfComputer指定笔记本电脑,台式机或平板电脑; total-Dollars表示销售的美元金额; number-of-Computers-Sold指定销售的此类计算机的数量 . 您的程序应将typeOfComputer参数转换为小写,因为输入将使用混合大小写指定 . [提示,包括,使用函数char tolower(char c); //如果c为大写,则以小写形式返回如果卖家不存在,则打印相应的消息(并读取并丢弃数据) . 参见样本输出 .

退出 - 退出命令 . 打印出售足以赢得美妙假期的人员名单 .

#include

#include

#include

#include "conio.h"

using namespace std;

const int MAX_SELLERS = 5;

const int NOT_FOUND = -1;

const float GOAL_IN_DOLLARS = 35000.0f;

const int GOAL_IN_COMPUTERS = 12;

class Seller

{

private:

float salestotal; // run total of sales in dollars

int lapTopSold; // running total of lap top computers sold

int deskTopSold; // running total of desk top computers sold

int tabletSold; // running total of tablet computers sold

string name; // name of the seller

public:

// default constructor

Seller()

{

name = "";

salestotal = 0.0;

lapTopSold = 0;

deskTopSold = 0;

tabletSold = 0;

}

// parameterized constructor and member functions

// Constructor:

// Initializes the Seller's name to newname.

// Initializes the Seller's salestotal to 0 and all integer fields to 0.

// Params: in

Seller ( string newname );

// Returns true if the seller's name is the same as nameToSearch;

// false otherwise.

// Params: in

bool SellerHasName ( string nameToSearch );

// Returns true if the seller sold GOAL_IN_COMPUTERS computers

// or GOAL_IN_DOLLARS sales or more.

// Params: NONE

bool WinsPrize ( );

// Adds the money and number of computers to the seller's accumulated

// sales total and number of computers sold based on the computer type.

// That is, if the computer type is “DESKTOP” then the desktop field is

// updated by numComputers, if the computer type is “LAPTOP” then the

// laptop field is updated by numComputers, if the computer type is

// “TABLET” then the tablet fields is updated by numComputers.

// Params: in, in, in

void UpdateSales ( float totalDollars, int numComputers,

string computerType );

// Print the salesperson's name, sales total, and number of

// computers sold.

// Params: NONE

void PrintSales ( );

};

Seller::Seller(string newname)

{

name = newname;

salestotal = 0.0;

lapTopSold = 0;

deskTopSold = 0;

tabletSold = 0;

}

bool Seller::SellerHasName ( string nameToSearch )

{

if(name == nameToSearch)

return true;

else

return false;

}

bool Seller::WinsPrize ( )

{

if(salestotal >= GOAL_IN_DOLLARS || (lapTopSold + deskTopSold +

tabletSold) >= GOAL_IN_COMPUTERS)

return true;

else

return false;

}

void Seller::UpdateSales( float totalDollars, int numComputers,

string computerType )

{

salestotal += totalDollars;

if(computerType == "DESKTOP")

deskTopSold += numComputers;

else if(computerType == "LAPTOP")

lapTopSold += numComputers;

else if(computerType == "TABLET")

tabletSold += numComputers;

}

void Seller::PrintSales ()

{

cout << name << " " << salestotal << "; sold " << lapTopSold <<

"LapTops, " << deskTopSold << " DeskTops, " << "and " <<

tabletSold << " Tablets." << endl;

}

class SellerList

{

private:

int num; // current number of salespeople in the list

Seller salespeople[MAX_SELLERS];

public:

// default constructor to make an empty list

SellerList()

{

num = 0;

}

// member functions

// If a salesperson with thisname is in the SellerList, this

// function returns the associated index; otherwise, return NOT_FOUND.

// Params: in

int Find ( string thisName );

void Add(Seller sellerName);

void Output(Seller sellerName);

};

int SellerList::Find(string thisName)

{

for(int i = 0; i < MAX_SELLERS; i++)

if(salespeople[i].SellerHasName(thisName))

return i;

return NOT_FOUND;

}

// Add a salesperson to the salespeople list IF the list is not full

// and if the list doesn't already contain the same name.

void SellerList::Add(Seller sellerName)

{

Seller(sellerName);

num++;

}

// Output the total value of computers sold and the total number of each

// type of computer sold for that seller. If the seller does not

// exist, print an appropriate message

void SellerList::Output(Seller sellerName)

{

}

int main()

{

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值