Display a product number, name (or description), and price for four retail products. They could be food, clothing, auto parts, plants, tools, kitchen utensils, or any other type of retail product. Prompt the user to enter the product number of each product they wish to buy, one at a time, and provide an escape character or number so that the user can let the program know when they are finished shopping and are ready to check out. When this escape character or number is entered, display the name (or description) and price of each product they chose, the subtotal, the sales tax (8% of subtotal), and the total after sales tax. The user should be able to buy up to a maximum of 10 items (the user may want more than one of a product). Additionally, the program must use object orientation (a class and/or struct or multiple classes and/or structs).

Recommended Answers

All 21 Replies

OK, sounds like a good project to work on. What have you done with it so far?

const int ITEMS = 10;
const int QUIT = 999;
int retailItem[ITEMS];
int salesTax, a;
double subTotal = 0;
double total;
salesTax = .08;

i tried to post the whole code but here were you post it was giving me syntax error so going to do it by parts

const int ITEMS = 10;
const int QUIT = 999;
int retailItem[ITEMS];
int salesTax, a;
double subTotal = 0;
double total;
salesTax = .08;

class RetailItem
{
private:
string description;
int itemNum;
double price;
public:

int getItem();
string getDescription();
double getPrice();
RetailItem(string,int,double);


void setItem(int);
void setdescription(string);
void setPrice(double);
};

RetailItem::RetailItem(string des,int item,double p)
{
description = des;
itemNum = item;
price = p;
}

int RetailItem::getItem()
{
return this->itemNum;
}

double RetailItem::getPrice()
{
return this->price;
}

string RetailItem::getDescription()
{
return this->description ;
}

void RetailItem::setItem(int item)

{
this->itemNum = item;
}

void RetailItem::setdescription(string desc)
{
this->description = desc;
}

void RetailItem::setPrice(double p)
{
this->price = p;
}

int main()
{
RetailItem obj1("Ecko Jacket",1,59.95);
RetailItem obj2("Polo Jeans",2,34.95);
RetailItem obj3("T-Shirt",3,24.95);
RetailItem obj4("Snicker shoes",4,50.25);

cout<<"#1     "<<obj1.getDescription()<<"       "<<obj1.getItem()<<"     $"<<obj1.getPrice()<<endl;
cout<<"#2     "<<obj2.getDescription()<<"        "<<obj2.getItem()<<"     $"<<obj2.getPrice()<<endl;
cout<<"#3     "<<obj3.getDescription()<<"           "<<obj3.getItem()<<"     $"<<obj3.getPrice()<<endl;
cout<<"#4     "<<obj4.getDescription()<<"     "<<obj4.getItem()<<"     $"<<obj4.getPrice()<<endl;

cout << "Enter first item number you would like to purchase or " << QUIT << " to quit ";
cin >>retailItem[salesTax];
while(salesTax < ITEMS &&  retailItem[salesTax] != QUIT)
{
    subTotal += retailItem[salesTax];
    ++salesTax;
if(salesTax < ITEMS)
{
    cout << "Enter next item number for purchase or " << QUIT << " to quit ";
    cin >>retailItem[salesTax];
}
cout << "The entered item numbers are: ";
for(a = 0; a < salesTax; ++a)
    cout << retailItem[a] << " ";
total =  subtotal * salesTax;
    cout << endl << "The total for your purchase is  " << total << endl;

return 0;
}

I clicked code on task bar and was able to insert what i have so far any help would be appreciated. thanks

help please really need get this done ASAP

Let's get started by getting the code properly indented, so that it is readable. A quick pass through the AStyle tool highlights one of the primary problems you've got right away:

const int ITEMS = 10;
const int QUIT = 999;
int retailItem[ITEMS];
int salesTax, a;
double subTotal = 0;
double total;
salesTax = .08;

class RetailItem
{
private:
    string description;
    int itemNum;
    double price;
public:
    int getItem();
    string getDescription();
    double getPrice();
    RetailItem(string,int,double);
    void setItem(int);
    void setdescription(string);
    void setPrice(double);
};

RetailItem::RetailItem(string des,int item,double p)
{
    description = des;
    itemNum = item;
    price = p;
}
int RetailItem::getItem()
{
    return this->itemNum;
}
double RetailItem::getPrice()
{
    return this->price;
}
string RetailItem::getDescription()
{
    return this->description ;
}
void RetailItem::setItem(int item)
{
    this->itemNum = item;
}
void RetailItem::setdescription(string desc)
{
    this->description = desc;
}
void RetailItem::setPrice(double p)
{
    this->price = p;
}

int main()
{
    RetailItem obj1("Ecko Jacket",1,59.95);
    RetailItem obj2("Polo Jeans",2,34.95);
    RetailItem obj3("T-Shirt",3,24.95);
    RetailItem obj4("Snicker shoes",4,50.25);
    cout<<"#1     "<<obj1.getDescription()<<"       "<<obj1.getItem()<<"     $"<<obj1.getPrice()<<endl;
    cout<<"#2     "<<obj2.getDescription()<<"        "<<obj2.getItem()<<"     $"<<obj2.getPrice()<<endl;
    cout<<"#3     "<<obj3.getDescription()<<"           "<<obj3.getItem()<<"     $"<<obj3.getPrice()<<endl;
    cout<<"#4     "<<obj4.getDescription()<<"     "<<obj4.getItem()<<"     $"<<obj4.getPrice()<<endl;
    cout << "Enter first item number you would like to purchase or " << QUIT << " to quit ";
    cin >>retailItem[salesTax];
    while(salesTax < ITEMS &&  retailItem[salesTax] != QUIT)
    {
        subTotal += retailItem[salesTax];
        ++salesTax;
        if(salesTax < ITEMS)
        {
            cout << "Enter next item number for purchase or " << QUIT << " to quit ";
            cin >>retailItem[salesTax];
        }
        cout << "The entered item numbers are: ";
        for(a = 0; a < salesTax; ++a)
            cout << retailItem[a] << " ";
        total =  subtotal * salesTax;
        cout << endl << "The total for your purchase is  " << total << endl;
        return 0;
    }

With suitable auto-indentation, it becomes apparent that you have a dangling close brace at the end of the main() function, a small but showstopping error. Fixing this, and compiling the program, shows off a few more things:

1) You have not #included any of the usual header files such as <iostream> and the like; you also do not have any scoping for the objects and classes that belong to the std namespace, nor do you have a using statement. Thus, most of the standard library components(std::string, std::cout, and so on) aren't going to be recognized. You need to recall that these things are all part of the standard library, not part of the core language itself.

2) On line 7, you have an assignment that isn't inside of a function. That is not acceptable C++ syntax, and will raise an error.

3) At the end of the main() function, you have subtotal instead of subTotal, which is small error but one which could have you going around in circles if you don't notice the difference in capitalization.

So, with a bit a clean-up, here is your code again:

#include <iostream>
#include <string>

const int ITEMS = 10;
const int QUIT = 999;
int retailItem[ITEMS];
int salesTax = .08, a;
double subTotal = 0;
double total;

class RetailItem
{
private:
    std::string description;
    int itemNum;
    double price;
public:
    int getItem();
    std::string getDescription();
    double getPrice();
    RetailItem(std::string,int,double);
    void setItem(int);
    void setdescription(std::string);
    void setPrice(double);
};

RetailItem::RetailItem(std::string des,int item,double p): description(des), itemNum(item), price(p)
{
    return;
}
int RetailItem::getItem()
{
    return this->itemNum;
}
double RetailItem::getPrice()
{
    return this->price;
}
std::string RetailItem::getDescription()
{
    return this->description ;
}
void RetailItem::setItem(int item)
{
    this->itemNum = item;
}
void RetailItem::setdescription(std::string desc)
{
    this->description = desc;
}
void RetailItem::setPrice(double p)
{
    this->price = p;
}

int main()
{
    RetailItem obj1("Ecko Jacket",1,59.95);
    RetailItem obj2("Polo Jeans",2,34.95);
    RetailItem obj3("T-Shirt",3,24.95);
    RetailItem obj4("Snicker shoes",4,50.25);
    std::cout<<"#1     "<<obj1.getDescription()<<"       "<<obj1.getItem()<<"     $"<<obj1.getPrice()<<std::endl;
    std::cout<<"#2     "<<obj2.getDescription()<<"        "<<obj2.getItem()<<"     $"<<obj2.getPrice()<<std::endl;
    std::cout<<"#3     "<<obj3.getDescription()<<"           "<<obj3.getItem()<<"     $"<<obj3.getPrice()<<std::endl;
    std::cout<<"#4     "<<obj4.getDescription()<<"     "<<obj4.getItem()<<"     $"<<obj4.getPrice()<<std::endl;
    std::cout << "Enter first item number you would like to purchase or " << QUIT << " to quit ";
    std::cin >>retailItem[salesTax];
    while(salesTax < ITEMS &&  retailItem[salesTax] != QUIT)
    {
        subTotal += retailItem[salesTax];
        ++salesTax;
        if(salesTax < ITEMS)
        {
            std::cout << "Enter next item number for purchase or " << QUIT << " to quit ";
            std::cin >>retailItem[salesTax];
        }
        std::cout << "The entered item numbers are: ";
        for(a = 0; a < salesTax; ++a)
            std::cout << retailItem[a] << " ";
        total =  subTotal * salesTax;
        std::cout << std::endl << "The total for your purchase is  " << total << std::endl;
        return 0;
    }
}

While this does not fix all of the existing issues with the code, it does at least get you to where you can compile the program without errors or warnings.

commented: thanks that helps. +0

This is for Dan's class right? IT 174?

its a code for store

Pull the other leg, now; it's got bells on it.

Seriously, there's little reason to try and hide the fact that this is a homework assignment; the description and requirements are pretty much a giveaway. We don't have a problem with students coming here to get help, quite the contrary. The problem is when someone drops their assignment and demands that we do the work for them, without showing any effort on their own part. While you certainly did that with your first post, you were able to get things going an showed your work right away without whining or dissembling, which counts for something at least. But this business of pretending that it isn't a class assignment when everyone here can see that it is, makes you look a bit skeevy to the regulars here. It doesn't get you anything but distrust and a mild contempt, something you don't want to earn if you intend to ask more questions here in the future.

commented: good one :) +0
commented: disembling? skeevy? I thought this was an English board! ;o) +14

Its suppose to be in the style of a STORE transaction thats what i meant a code for store sorry i tend to use short words for description at times

Sorry man I was just going to say that he wanted for the functions to be written outside of main(). Just trying to help out because I had it written everything in main() and he told me to make seperate functions; Based off the structs or classes depending how we write it. Good luck!

I been working on this program for a while now and just everytime its giving me a harder time with it.

I wrote a while loop for user input after the items are displayed, and saved a value so it can store the user input numbers in an array(sorta like you have it in your main() function. After that I did a for loop including if else statements. I.E. if( x == something) \n cout<<name<<somespace in between or use setw(some#)<<price<<endl; and kept doing that for all 4 products. Then wrote another for loop of if else statements(almost identical to the above if statement) to add the prices to a double subTotal variable. Initialzing subTotal = 0 first. But I wrote this in a function outside of main(). e-mail Dan if you need more help. Hope I helped a bit.

the one i wrote displays the items but i can't get it to hold them and add them together. I been emailing him but he says it like if we should be professionals at C++ so just gets me more confuse. also he just keeps saying its your program can't help you much.

Yeah dude, I had a hard time writing this program. If your program up top is still the same, I think your subtotal = the item numbers not the prices. And when you display the total (for when you add up all the prices) you want to multiply it by .08 for Tax and then subTotal * 1.08 to show the actual total with tax included.

cout << "Enter first item number you would like to purchase or " << QUIT << " to quit ";
cin >>retailItem[salesTax];
while(salesTax < ITEMS && retailItem[salesTax] != QUIT)
{
subTotal += retailItem[salesTax];
++salesTax;
if(salesTax < ITEMS)
{
cout << "Enter next item number for purchase or " << QUIT << " to quit ";
cin >>retailItem[salesTax];
}

Right after this part you would make a for loop that includes if else statements so like,
for(int i = 0; i < salesTax; ++i)//you do this because you want to circulate through how many times the user inputs an item number or up until they enter the sentinal value. This for loop is to display the items the user inputs. It works on mine like this I'm hoping it'll work on yours too.

for(int i = 0; i < salesTax; ++i
{
    if(retailItem[i] == itemnumber)
    cout<<"item name"<<setw(10)<<"$"<<(your item price)<<endl;
    else
    if(etc.....
    up till your 4 products are assigned to your item number.

 }

then do another for loop to assign values again and save them into a double sub value and initialize it to 0 first. It's going to look like the one above in the example I wrote. I hoped this helped.

so how many loops would it include in whole program? thats where am getting confuse doing loops and loops.

Well I had 1 while loop and 2 for loops. I used another for loop for my display function, but it all depends how you write your program. You might have to adjust to make it work.

I still been working off the one i uploaded on this page. the harder part is that i dont have access to a compiler to compile it to see whats wrong.

Dang that's sucks man. You couldn't download code blocks? The only thing left I can say is good luck man! At least turn in the pseudocode and the program and try to get points with what you got if you don't finish, but I'm sure you can. Just keep working at it. Remember its due today.

well i did download it but not a computer i had access to everyday but thanks for the help tho yea i might just turn in what i have and that would be the end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.