I'd appreciate some help please!
What I need to do is set up a computer system for a shop where the user will see a menu like this:
1) Add Item
2) Sold Item
3) Print List
4) Find Item
5) Exit
Please choose:
If an item is bought for the shop, the user will select 1 from the menu and then enter the three attributes
1 - Serial No
2 - Description
3 - Price
When an item is sold, the user will select 2 from the menu and enter the serial no of item sold
When a description of an item was needed, user will selct 4 from the menu and enter serial no
When a list of entire stock is neede, user will press 3 and all stock will be printed to screen.
Here is my code so far:
#include<iostream>
#include<iomanip>
#include<cstring>
#include <cstdlib>
using namespace std;
const int MAX = 5000;
void addItem(string s[], string d[], double p[], int & size);
void printArray(string s[], string d[],double p[],int size);
void findItem(string s[], string d[], double p[], int size);
int main()
{
string s [MAX];
string d [MAX];
double p [MAX];
int size = 0;
char choice;
cout << fixed << setprecision(2);
do
{
system ("CLS");
cout << endl << endl << endl << setw(40) << "Menu";
cout << endl << setw(40) << "1 : " << "Add Item ";
cout << endl << setw(40) << "2 : " << "Sold Item ";
cout << endl << setw(40) << "3 : " << "Print List ";
cout << endl << setw(40) << "4 : " << "Find Item ";
cout << endl << setw(40) << "5 : " << "Exit ";
cin >> choice;
cin.get();
switch (choice)
{
case '1' : addItem(s,d,p,size);
break;
case '2' : cout << endl << setw(40) << "Sold Item " << endl;
cin.get();
break;
case '3' : printArray(s,d,p,size);
cin.get();
break;
case '4' : cout << endl << setw(40) << "Find Item " << endl;
cin.get();
break;
}
}while (choice != '5');
return 0;
}
void printArray(string s[], string d[],double p[],int size)
{
cout << endl << endl << endl << setw(40);
cout << setw(10) << "" << left << setw(15) << "SERIAL NO " << setw(35) << "DESCRIPTION " << right << setw(10) << "PRICE EUROS " << endl;
for(int i = 0; i < size; i++)
{
cout << setw(10) << "" << left << setw(15) << s[i] << setw(35) << d[i] << right << setw(10) << p[i] << endl;
if((i+1)%4 == 0)
{
cout << endl;
}
}
cin.get();
}
void addItem(string serials[], string descriptions[], double prices[], int & size)
{
if(size >= MAX)
{
cout << "Cannot add item. Array is full. ";
cin.get();
}
else
{
cout << "Input Serial Number ";
getline(cin, serials[size]);
cout << "Input Description ";
getline(cin, descriptions[size]);
cout << "Input Price ";
cin >> prices[size];
cin.get();
size++;
}
void findItem(string s[], string d[], double p[], int size);
int found;
string to_find;
string BySerial;
found = find BySerial (to_find, s, 5);
if (found = -1)
{
cout << "Item with serial number " << to_find << "not in database. " << endl;
cin.get();
}
else
{
cout << descriptions[found];
}
int find BySerial (string to_find, int s[], int size);
{
int found = -1;
for (int i = 0, i < size, i++);
if (serials[i] == to_find);
{
found = [];
break;
}
return found;
}
}
Help with arraysHelp with arrays
Page 1 of 1
1 Replies - 461 Views - Last Post: 26 November 2007 - 12:36 PM
Replies To: Help with arrays
#2
Re: Help with arrays
Posted 26 November 2007 - 12:36 PM
What errors are you encountering? Or were you looking for help in some part of the implementation?
Also, please post your code in [ code] [ /code] blocks; it makes it much easier to read.
Hit "edit post", highlight all your code, and press the "#" button on the toolbar.
Also, please post your code in [ code] [ /code] blocks; it makes it much easier to read.
Hit "edit post", highlight all your code, and press the "#" button on the toolbar.
This post has been edited by MorphiusFaydal: 26 November 2007 - 12:38 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|