Making A List

So as the story goes, I was picked for an entry in a school group to do an assignment on C++. I had 20 days to learn as much as I could and complete the assignment. I used up all my time, but the assignment still frustrates me. Anyways, I was just wondering if anyone could point me in the right direction.

Ok, so the assignment went something like this: Your school needs help keeping track of their items, make a program that can provide a list of items. Your program needs to be able to add items, display last item entered, display all items, and display a random item. Needless to say you'll need to have a basic menu and should include exit as an option.

P.S. The assignment is over and this is purely curiosity.

Thanks,
Atraii
I would go for standard containers: http://www.cplusplus.com/reference/stl/
std::deque can easily add items and allows subscripting and that makes getting a random item really easy
Why don't you post the code you wrote (and is ostensibly non-working)?
Thank you for the quick reply and I'm sorry for the long delay in response. The code I did write was terrible, and did not complete it's job whatsoever, but thats what I get for trying to learn what I could of c++ in 20 days. Anyways, here is the code:(...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct items_t {
  string title;
}list;

void printitem (items_t item);
void Menu();
void AddItem();
void RanItem();

void Menu()
{
	enum MenuChoice
	{
		mcExit = 0,
		mcAddItem = 1,
		mcAllItem = 2,
		mcRanItem = 3
	};

	int	choice = 0;
	do
	{
		cout << "Item Management System\n";
		cout << "Written by #2200760012\n\n";
		cout << "   1. Add Item\n";
		cout << "   2. Display All Items\n";
		cout << "   3. Display Random Item\n";
		cout << "   0. Exit\n\n";
		cout << "Enter your choice: ";
		cin  >> choice;
		cin.ignore();

		switch (choice)
		{
		case mcAddItem:
			{
			    cout << "Add Item: \n";
				AddItem();
				break;
			}

		case mcAllItem:
			{
				printitem (list);
				break;
			}

		case mcRanItem:
			{
				RanItem();
				break;
			}

		case mcExit:
			{
				cout << "See you next time!\n";
				break;
			}

		default:
			cerr << "Oops, wrong choice\n\n";
		}
	}
	while (choice != mcExit);
}

void AddItem()
{
    int n;

    for (n=0; n<1; n++)
    {
        cout << "Enter title: ";
        getline (cin, list.title);
    }
    cout << "\nYou have entered these items:\n";
    for (n=0; n<1; n++)
    printitem (list);
}

void RanItem()
{
}

int main ()
{
    Menu();
}

void printitem (items_t item)
{
  cout << item.title << endl;
}
Last edited on
Topic archived. No new replies allowed.