【发布时间】:2015-10-25 01:05:44
【问题描述】:
我遇到了以下问题:
medcost = Pharm1.getCost();
surgcost = Surg1.getCost();
PatientAccount PatAct1(double &medcost, double &surgcost, int &daysanswer);
finaltotal = PatAct1.getCost();
“Surg1”“Pharm1”和“PatAct1”都带有红色下划线,在 Visual Studio 中出现错误“表达式必须具有类类型”。
我搜索了这个错误,但我不太明白答案,因为我还没有找到向量。有人可以帮我理解为什么这些不只是返回函数返回并将其放在左侧的变量中吗?
如果这是一个非常愚蠢的问题,我很抱歉,我整个星期都被难住了!
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
class Pharmacy
{
private:
int type;
double cost;
public:
// Declare functions
Pharmacy();
Pharmacy(int &t);
double getCost();
// Actual functions
Pharmacy::Pharmacy()
{
type = 0;
cost = 0.00;
}
Pharmacy::Pharmacy(int &t)
{
type = t;
switch (type)
{
case 1:
cost = cost + 100.00;
break;
case 2:
cost = cost + 200.00;
break;
case 3:
cost = cost + 300.00;
break;
case 4:
cost = cost + 400.00;
break;
case 5:
cost = cost + 500.00;
break;
}
}
double Pharmacy::getCost()
{
return cost;
}
};
class Surgery
{
private:
int type;
double cost;
public:
// Declcare functions
Surgery();
Surgery(int &t);
void setType(int &t);
double getCost();
// Actual functions
Surgery::Surgery()
{
type = 0;
cost = 0.00;
}
Surgery::Surgery(int &t)
{
type = t;
switch (type)
{
case 1:
cost = 100.00;
break;
case 2:
cost = 200.00;
break;
case 3:
cost = 300.00;
break;
case 4:
cost = 400.00;
break;
case 5:
cost = 500.00;
break;
}
}
void Surgery::setType(int &t)
{
type = t;
switch (type)
{
case 1:
cost = 100.00;
break;
case 2:
cost = 200.00;
break;
case 3:
cost = 300.00;
break;
case 4:
cost = 400.00;
break;
case 5:
cost = 500.00;
break;
}
}
double Surgery::getCost()
{
return cost;
}
};
class PatientAccount
{
private:
int days;
double medcost;
double surgcost;
double total;
double rate;
public:
// Declare functions
PatientAccount();
PatientAccount(double &c1, double &c2, int &d);
double getCost();
// Actual functions
PatientAccount::PatientAccount()
{
days = 0;
medcost = 0;
surgcost = 0;
total = 0;
rate = 40.00;
}
PatientAccount::PatientAccount(double &c1, double &c2, int &d)
{
medcost = c1;
surgcost = c2;
rate = 40.00;
days = d;
total = (days * rate) + medcost + surgcost;
}
double PatientAccount::getCost()
{
return total;
}
};
int main()
{
// Declare variables
int menuanswer = 0;
int surgeryanswer = 0;
int medicationanswer = 0;
int daysanswer = 0;
double finaltotal = 0;
bool loop = false;
bool boolsurg = false;
bool boolmed = false;
bool booldays = false;
double medcost = 0;
double surgcost = 0;
// Declare class variables
class Surgery Surg1;
class Pharmacy Pharm1;
class PatientAccount PatAct1;
// Menu loop
do
{
cout << "Welcome to the menu, what would you like to do?" << endl;
cout << "Type 1 to enter surgery type" << endl;
cout << "Type 2 to enter medication type" << endl;
cout << "Type 3 to enter number of days stayed" << endl;
cout << "Type 4 to check out and see all costs" << endl;
cin >> menuanswer;
switch (menuanswer)
{
case 1:
cout << "What kind of surgery did you have?" << endl;
cout << "Press 1 for foot" << endl;
cout << "Press 2 for brain" << endl;
cout << "Press 3 for leg" << endl;
cout << "Press 4 for knee" << endl;
cout << "Press 5 for hand" << endl;
cin >> surgeryanswer;
Surgery Surg1(int &surgeryanswer);
boolsurg = true;
loop = false;
break;
case 2:
cout << "What kind of medication did you use?" << endl;
cout << "Press 1 for pain killers" << endl;
cout << "Press 2 for heachach pills" << endl;
cout << "Press 3 for childrens medication" << endl;
cout << "Press 4 for advil" << endl;
cout << "Press 5 for tylenol" << endl;
cin >> medicationanswer;
Pharmacy Pharm1(int &medicationanswer);
boolmed = true;
loop = false;
break;
case 3:
cout << "How many days did you stay at the hospital?" << endl;
cin >> daysanswer;
booldays = true;
loop = false;
break;
case 4:
if ((booldays == true) && (boolmed == true) && (boolsurg == true))
{
cout << "It looks like you're ready to check out" << endl;
medcost = Pharm1.getCost();
surgcost = Surg1.getCost();
PatientAccount PatAct1(double &medcost, double &surgcost, int &daysanswer);
finaltotal = PatAct1.getCost();
cout << "Your total cost is $" << endl;
loop = true;
}
else
{
cout << "ERROR - You must give all required information - surgery type, medications, and days" << endl;
loop = false;
}
}
} while (loop == false);
}
【问题讨论】:
标签: c++