לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 20-05-2007, 10:34
  Omegajam Omegajam אינו מחובר  
 
חבר מתאריך: 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;
}


תודה
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #3  
ישן 20-05-2007, 11:47
  Omegajam Omegajam אינו מחובר  
 
חבר מתאריך: 08.03.03
הודעות: 6
בתגובה להודעה מספר 1 שנכתבה על ידי Omegajam שמתחילה ב "C++ lab problem"

קוד:
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; }
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 17:10

הדף נוצר ב 0.03 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2026 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר