
20-05-2007, 10:34
|
|
|
|
חבר מתאריך: 08.03.03
הודעות: 6
|
|
|
C++ lab problem
היי לכולם!
יש לי בעייה בפתרון של שאלה מLAB
שאלה:
The “main” of the C++ program attached to this assignment expects a class called “item.” This class
must have methods for “enter” and for “print.” Below is a description of what each method should do:
item.enter() should allow the user to enter:
? the item's name
? the item's price
? the item's discount as a percentage of its cost
? the item's category
Note that the discount percentage should not be more than 10% and that the category is limited to
“food,” “clothing” or “other.”
item.print() should print the following in the order specified, all on one line:
? the item's name
? the item's discount percentage
? the tax on the item
? the total cost of the item, taking into consideration its discount percentage and tax
Note that only items in the category “clothing” and “other” are taxed. Items in the category “food” are
not taxed.
Your “main” must look like this:
int main () {
item cart[3];
int i = 0;
while (i < 3) {
cart[i++].enter();
}
i = 0;
cout << "Item: Name price discount tax total" << endl;
while (i < 3) {
cart[i++].print();
}
return 0;
}
פתרון שלי, (אני ממש חדש ב C++)
// header.h (stand alonen program)
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string getName()
{
string name;
cout << "Enter name: " ;
cin >> name;
return name;
}
string name = getName();
double RequestOriginalPrice()
{
double Price;
Console::Write("Enter the original price: $");
Price = double: arse(Console::ReadLine());
return Price;
}
double RequestDiscountRate()
{
double Discount;
Console::Write("Enter discount rate(0.00 to 100.00): ");
Discount = double: arse(Console::ReadLine());
return Discount;
}
double RequestTaxRate()
{
double Tax;
Console::Write("Enter the tax rate(0.00 to 100.00): ");
Tax = double: arse(Console::ReadLine());
return Tax;
}
int main ()
{
item cart[3];
int i = 0;
while (i < 3) {
cart[i++].enter();
}
i = 0;
cout << "Item: Name price discount tax total" << endl;
while (i < 3)
{
cart[i++].print();
}
return 0;
}
תודה
|