|
-
December 28th, 2011, 11:31 AM
#1
To call file
at first, plec correct me this one...
Code:
std::string explanation; // this upper coding
char explanation; //after entering void to display
if(item_code=='A')
explanation='BABY WEAR';
else if(item_code=='B')
explanation='CHILDREN WEAR;
else if(item_code=='A')
explanation='LADIES WEAR';
else if(item_code=='A')
explanation='MENSWEAR';
BABY WEAR and others was error, what should i put?
plz correct my coding above one first, it it was take long time to solve coding down there.
sorrt, bcoz i really dont know..
plz correct me, im running my coding right now with non-stop study, and always refresh this page...
this is of mine that full, the new one...
Code:
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<string>
using std::cout;
using std::cin;
using std::endl;
struct RECORD
{
std::string item_code;
std::string item_number;
std::string explanation;
double price;
}input[10000];
void addRecord(RECORD input[], int &arraycounter);
void printRecord(RECORD input[]);
void printAllRecord(RECORD input[]);
int main()
{
std::fstream submit;
submit.open("jualan.dat",std::ios::in);
submit.seekg(0, std::ios::beg);
int arraycounter=0;
do
{
submit>>input[arraycounter].item_number>>input[arraycounter].item_code>>input[arraycounter].price;
arraycounter++;
}
while(submit.good());
submit.close();
arraycounter--;
{
int menuEnter;
do
{
cout<<"\tFamily Outfit Shop"<<endl;
cout<<"\t MAIN MENU"<<endl;
cout<<"\t-------------------"<<endl;
cout<<" 1 = Add a record\n";
cout<<" 2 = Displays sales report for a category\n";
cout<<" 3 = Displays sales report for all categories\n";
cout<<" 4 = Exit";
cout<<"\nEnter Menu Number : ";
cin>>menuEnter;
if(menuEnter==1)
addRecord(input, arraycounter);
else if (menuEnter==2)
printRecord(input);
else if (menuEnter==3)
printAllRecord(input);
}
while (menuEnter!=4);
return 0;
}
void addRecord(RECORD input[], int arraycounter);
{
char item_code; // code category
char item_number; // code number category
cout<<"Enter code category : \n";
cin>>input[arraycounter].item_code;
cout<<"Enter code number of category : \n";
cin>>input[arraycounter].item_number;
arraycounter++;
}
void printRecord(RECORD input[]);
{
char item_code, item_number;
char explanation;
float price, total_sales;
cout<<"Please enter category code : "<<endl;
cin>>item_code;
if(item_code=='A')
explanation==BABY WEAR;
else if(item_code=='B')
explanation='CHILDREN WEAR';
else if(item_code=='A')
explanation='LADIES WEAR';
else if(item_code=='A')
explanation='MENSWEAR';
cout<<"SALES REPORT FOR "<<explanation<<endl;
cout<<"\nItem Number\t\tPrice" << endl;
cout<<"------------------------------"<<endl;
cout<<item_code<<item_number<<"\t\t"<<price<<endl;
cout<<"------------------------------"<<endl;
cout<<"Total Sales\t\t"<<total_sales<<endl;
cout<<endl;
switch(item_code)
{
case'A':
if(item_number==101)
{
price=10.00;
}
if(item_number==102)
{
price=5.00;
}
break;
case'B':
if(item_number==101)
{
price=12.00;
}
if(item_number==104)
{
price=20.00;
}
if(item_number==105)
{
price=20.00;
}
break;
case'C':
if(item_number==103)
{
price=12.00;
}
break;
case'D':
if(item_number==101)
{
price=12.00;
}
break;
}
}
void printAllRecord(RECORD input[]);
{
cout<<"SALES REPORT FOR ALL CATEGORIES"<<endl;
cout<<"\nCategory\t\tSales" << endl;
cout<<"------------------------------"<<endl;
cout<<explanation<<"\t\t"<<price<<endl;
cout<<"------------------------------"<<endl;
cout<<"Total Sales\t\t"<<totalSales<<endl;
cout<<endl;
}
this is the question. no.1, no problem, but no 2, and 3, but also 4. how to exit? but no1, does can repeat or back to menu? bcoz to add many record?
Family Outfit Shop decided to create a computerized system to maintain the shop inventory. The shop sells variety of garments and the garments are categorized to a particular group. Each category is given a code and the explanation for each code is given bellow.
CODE | EXPLANATION
A | baby wear
B | children wear
C | ladies wear
D | menswear
You as a programmer are required to write a program which contains a menu as bellow:
Family Outfit Shop
MAIN MENU
1)Add a record
2)Display sales report for a category
3)Display sales report for all category
4)Exit
Guideline
The program should give the user an option to choose any sub menu and it would only stop when the user choose the Exit sub menu.
1)Add a record
This sub menu will add a sales record for a particular garment into a file name jualan.dat. Each record consists of three fields which are item number, item code and price. The user may add more than one record at a time. You can use a sentinel value to control the loop. Assumed that file jualan.dat already exists. Example of file jualan.dat is shown as bellow:
A101= A =10.00
B101= B = 12.00
A102 =A= 5.00
B105= B = 17.00
C103 =C= 40.00
D101 =D = 15.00
B104 =B =20.00
2)Display sales report for a category
In this sub menu the sales report of a particular category will be displayed. The category shall be chosen by the user.
SALES REPORT FOR BABY WEAR
Item Number | Price
A101 | 10.00
A102 | 5.00
Total Sales | 15.00
3)Display sales report for all category
In this sub menu the sales report for all the categories will be displayed.
SALES REPORT FOR ALL CATEGORIES
Category Sales
Baby wear 15.00
Children wear 49.00
Ladies wear 40.00
Menswear 15.00
Total Sales 119.00
4)Exit
End of program.
-
December 28th, 2011, 12:38 PM
#2
Re: To call file
Single quotes are used for char variables. Double quotes are used for string literals.
Please use real words. It doesn't take much longer to type "please" than "plz".
-
December 28th, 2011, 07:36 PM
#3
Re: To call file
so this should be
string explanation
plz complete ur solving, just in case, only that, bcoz im not that smart
-
December 29th, 2011, 09:53 PM
#4
Re: To call file
You don't need to translate A = baby wear or B =children wear..etc.. so you can avoid many lines of codes and problems with your translation, just use whatever variable which stands for "item code", you use a loop(while, for...) and if item_code =='A' then display the record contains that item code(menu 3) or calculate the sum of all prices then display them as "cout<<"Children Wear:" <<sum;", isn't it much simpler?
Again, you should use proper coding references along with right compiler, try to find new c++ book and use Microsoft visual C++ 2010:
replace all these lines:
Code:
using std::cout;
using std::cin;
using std::endl;
with
Code:
using namespace std;
and why did you include those without using them? don't.
Code:
#include<cstdlib>
#include<iomanip>
you dont need use string in this problem, go ahead and use char abcxyz[SIZE] with SIZE was declared as constant-global var, ex: const int SIZE = 50
did you try again, any new updated code? turn on your private message option if you want more helps.
Last edited by longbodie99; December 30th, 2011 at 02:55 AM.
-
December 29th, 2011, 11:47 PM
#5
Re: To call file
 Originally Posted by longbodie99
Again, you should use proper coding references along with right compiler, try to find new c++ book and use Microsoft visual C++ 2010:
Before you even download another compiler, what compiler are you using now?
 Originally Posted by longbodie99
replace all these lines:
Code:
using std::cout;
using std::cin;
using std::endl;
with
Code:
using namespace std;
That could make life easier, but it is not necessary since you are fully qualifying the other names, e.g., you wrote std::string instead of string. Of course, if you wanted to, you could also add a:
instead of replacing the using declarations with a using directive.
EDIT:
 Originally Posted by longbodie99
you dont need use string in this problem, go ahead and use char abcxyz[SIZE] with SIZE was declared as constant-global var, ex: const int SIZE = 50
No, don't bother making life more difficult for yourself: stick to std::string.
 Originally Posted by longbodie99
turn on your private message option if you want more helps.
Getting help privately means that there is no peer review for the help given you. This is not a personal strike against longbodie99, but as you can see I disagree with some of the advice that longbodie99 has given, and indeed I have been wrong too when providing help.
Last edited by laserlight; December 30th, 2011 at 03:19 AM.
-
December 30th, 2011, 07:57 AM
#6
Re: To call file
 Originally Posted by khelly
so this should be
string explanation
plz complete ur solving, just in case, only that, bcoz im not that smart
From the Before you post announcement at the top of the forum.
Use real grammer. If you use things like "u r gr8", you are going to be seen as unprofessional. Worse, many of the people who speak English as a second language may not understand what you are saying -- and thus won't be able to response.
-
December 30th, 2011, 08:29 AM
#7
Re: To call file
Use real grammer. If you use things like "u r gr8", you are going to be seen as unprofessional. Worse, many of the people who speak English as a second language may not understand what you are saying -- and thus won't be able to response.
I'd say even more. You are going to be seen as showing no respect to norms of community. And thus the people who really may help won't be willing to response.
Best regards,
Igor
-
December 30th, 2011, 12:56 PM
#8
Re: To call file
@longboodie, open ur gmail msg bro.. plz...
-
December 30th, 2011, 01:06 PM
#9
Re: To call file
 Originally Posted by khelly
@longboodie, open ur gmail msg bro.. plz...
Why are you being so stubborn? You're alienating people that would otherwise be willing to help. Good luck with that strategy in the real world.
-
December 30th, 2011, 01:24 PM
#10
-
December 30th, 2011, 03:04 PM
#11
Re: To call file
@laserlight: I'm using visual c++ 2010 express, I was trying to help the thread owner, with those simple problems like this, I just use:
Code:
#include<iostream>
#include<fstream>
using namespace std;
that was what I saw in the book and we don't need to use any string var in this problem, so don't need to include or worry anythings about string, just use char variable, THAT IS, I don't see any variable that need to be longer than 2 letters, so the struct can be simply declared like this:
Code:
struct RECORD
{
char item_code; //because it only is A or B or C or D
int item_number; //because it is only integer digits
//you dont need any string explanation here
double price;
}input[10000];
one more thing that thread starter was wrong is that:
Code:
switch(item_code)
{
case'A':
if(item_number==101)
{
price=10.00;
}
if(item_number==102)
{
price=5.00;
}
break;
case'B':
if(item_number==101)
{
price=12.00;
}
if(item_number==104)
{
price=20.00;
}
if(item_number==105)
{
price=20.00;
}
break;
case'C':
if(item_number==103)
{
price=12.00;
}
break;
case'D':
if(item_number==101)
{
price=12.00;
}
break;
}
these lines were non sense, because item code and price can be anything that given by user, for example item code can be 202, 404, 500, 302... and price can be $100. $100000, $9999....
these line just showed the example that problem given, it is just example.
you got problem with MENU 2 and 3? Here is my suggestion:
-for MENU 2: display single category: we need a function
Code:
void display_single(RECORD *xxx, char yyy, int arraycounter)
{
double sum =0;
for(int i=0, i<arraycounter,i++)
{
if(xxx[i].itemcode==yyy)
{
sum = sum+ xxx[i].price;
//display xxx[i].itemcode <<xxx[i].itemnumber <<xxx[i].itemprice ... as desired
}
}
//display sum here as total sale.....as desired
}
}
and in the main function, call that function and replace 'yyy' = A or B,C,D as you want
ex: if you want to show BABy WEAR: display_single(input, 'A', int arraycounter) ....
-for MENU 3: display all record: we also need function:
Code:
void display_all(RECORD *add, int arraycounter) //dont worry about 'add', it just a name, can be whatever you like....
{
double sumA = 0, sumB=0, sumC=0, sumD=0, TotalSale=0;
for(int i=0; i<arraycounter; i++)
{
if(add[i].ItemCode=='A'||add[i].ItemCode=='a') sumA=sumA+add[i].Price;
else if(add[i].ItemCode=='B'||add[i].ItemCode=='b') sumB=sumB+add[i].Price;
//else ....same for C and D.....
}
//display as desired.......................................
cout <<" Babies wear"<<" $"<<sumA<<endl;
//and same for b,c,d, total sale
}
in main function you simple call that function for menu 3
Last edited by longbodie99; December 30th, 2011 at 03:20 PM.
-
December 31st, 2011, 12:46 AM
#12
Re: To call file
cannot run, but i will try...
-
December 31st, 2011, 04:08 AM
#13
Re: To call file
 Originally Posted by longbodie99
so don't need to include or worry anythings about string, just use char variable, THAT IS, I don't see any variable that need to be longer than 2 letters
Instead of recommending that std::string be changed to char, you recommended the use of a "char abcxyz[SIZE] with SIZE was declared as constant-global var, ex: const int SIZE = 50". In other words, you saw that there was a "variable that need to be longer than 2 letters". In such cases, it makes sense to prefer std::string to char[SIZE], unless there are special reasons otherwise.
 Originally Posted by longbodie99
we don't need to use any string var in this problem
The variable named explanation, which perhaps would be better termed "name" or "description", is a string, despite your attempt to explain this away with the comment that "you dont need any string explanation here".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|