School Project

I need to create a program with c++ m to keep a list of available items in a sports goods store. For each item, the following information must be stored: Name, Manufacturer, Price, Available items. The program should support the following features, as a text menu from which the user can choose:
• Enter a new item in the list
• Search by Manufacturer of an item
• Sort items in the list by Name
• Display the current content of the list
----------
I have to work with structures and yeah thats it. I basically started making the menu with a switch case and thats where I'm at. I'm very very new at these stuff so I would like a few pointers in how I can make all of those four options. Maybe example codes or links, anything that would help me in my endeavour. Thanks in advance.
Hello icaman,

It looks like you have a good start. Post what code you have so far. That is better than guessing what you might have done. And if you do not know:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.

For the struct if you textbook does not give you the answers that you need try this: http://www.cplusplus.com/doc/tutorial/structures/ There is examples of structs and at the end a program using the struct.

I do have one question: Have you learned about functions yet?

Once yo have the menu working the way that you want I would work on getting the user input and putting that information into the struct.

When you have information in the struct you will need to store this struct in an array or a vector would be a better choice.

When you have all the information that you want the "Display" is easy and the last two I would work on is the "Search" and "Sort".

Hope that helps,

Andy
You need to make a structure say 'ITEMS'. Under ITEMS declare the information that you want to store such as name, price etc. Make a vector in the main function with <ITEMS>.
-> That's pretty much all you need the rest is just logic.

1) For the menu, you would make a function that displays the information and returns the input after verifying that it's a valid input. You can use pass by reference. Don't bother about functions if you haven't learn it yet. Then just use switch case like you said.

2) For adding an item, (again make a function if you have learnt about it) make a temporary ITEMS object and ask the user for the various required inputs like price and then directly read the inputs into the object (eg. cin >> object.price). After getting all information, simply push the object into the vector we had.

3) For searching by Manufacturer's name you simple need to compare the given name with the manufacturer's name from each element of the vector.

4) Sort the elements of the vector based on their name parameter.

5) Simply print out all parameters of each element in the vector.

Good luck ;)
Is this program something new or is it a continuation of http://www.cplusplus.com/forum/beginner/243374/ ?
I started over ( That posted right there is to be completely ignored Andy ) Thanks for all the responses guys, Ill keep them all in mind
Last edited on
Hello icaman,

OK. So post what you have done so far. We all need a place to start from.

Andy
Topic archived. No new replies allowed.