473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

program help

dan
I need help in figuring out what to do for this program, it is a
program that reads book id, unit price, book purchased, book sold,
book returned, and city(respectively). It is a control break program
that prints a report for each city on a separate screen with a total,
then at the end it has a grand total. It prints to the screen and an
output file.
Input file looks like (the char is the city)
200 1.40 30 13 1 B
201 7.50 13 1 0 B
202 2.50 50 23 3 B
198 5.00 45 15 2 C
200 1.40 13 2 0 C
201 7.85 15 5 0 N
202 2.25 50 30 1 N
155 3.50 11 5 1 P

sample output
Store: Bloomington (which is all the ones with the letter B at the
end)
ID Price Purchase Sold Returns Inventory Value
200 1.40 30 13 1 25.20
201 7.50 13 1 0 90.72
202 2.50 50 23 3 76.35
Total: 93 37 4 192.27
then one for city C, N, and P
Then a grand total for all the citys put together

Here is what i got so far that is probably not close to working

#include <iostream>
#include <cctype>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

void Header();
void ReadInput(istream& ins, int& id, double& unitPrice, int&
purchased, int& sold,
int& returned, char& city);

int main()
{
ifstream infile;
ofstream outfile;

infile.open("a:\\comics.txt");
if (infile.fail( )) {
cout << "Input file opening failed.\n";
system("pause");
exit(1);
}
outfile.open("a:\\inventory.txt");
if (outfile.fail( )) {
cout << "Output file opening failed.\n";
system("pause");
exit(1);
}
// format double on the screen to print with 2 decimals
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// format doubles in the output file to print with 2 decimals
outfile.setf(ios::fixed);
outfile.setf(ios::showpoint);
outfile.precision(2);

int id, purchased, sold, returned;
double unitPrice;
int totalBooks = 0;
double invVal = 0;
char city;
int totalPurchased = 0, totalSold = 0, totalReturned = 0;
double totalInvVal = 0;
Header();
ReadInput(infile, id, unitPrice, purchased, sold, returned, city);
totalBooks = (purchased - sold + returned);
invVal = (unitPrice * totalBooks);
bool first = true;
int oldCity = 0;
while(infile >> id >> unitPrice >> purchased >> sold >> returned >>
city);
{
infile >> city;
//if (!first && oldCity != city)
{
switch(city)
{
case 'B':
cout << "Store: Bloomington";
break;
case 'N':
cout << "Store: Normal";
break;
case 'C':
cout << "Store: Champaign";
break;
case 'U':
cout << "Store: Urbana";
break;
case 'P':
cout << "Store: Peoria";
break;
}
cout << endl << endl;
totalPurchased += purchased;
totalSold += sold;
totalReturned += returned;
totalInvVal += invVal;
outfile << "ID\t" << "Price\t" << "Purchase " << "Sold " <<
"Returns "
<< "Inv. Value\n";
cout << "ID\t" << "Price\t" << "Purchase " << "Sold " <<
"Returns "
<< "Inv. Value\n";
outfile << id << "\t" << unitPrice << "\t" << purchased << "\t "
<< sold << "\t "
<< returned << "\t " << invVal;
cout << id << "\t" << unitPrice << "\t" << purchased << "\t " <<
sold << "\t "
<< returned << "\t " << invVal;
cout << endl << endl;
cout << "Totals\t\t" << totalPurchased << totalSold << totalReturned
<< totalInvVal;
}
first = false;
oldCity = city;
}

infile.close( );
outfile.close( );
cout << endl << endl;
system("pause");
return EXIT_SUCCESS;
}
void ReadInput(istream& ins, int& id, double& unitPrice, int&
purchased,
int& sold, int& returned, char& city)
{
ins >> id >> unitPrice >> purchased >> sold >> returned >> city;

}
void Header()
{
using namespace std;
cout << "\t\tCosmic Comics Inventory Report by Store\n";
cout << "\t\t Prepared by Daniel Buenger\n";
cout << "\t\t\t Date: Oct/30/2003\n\n";
}

Thanks in advance,
B14
Jul 19 '05 #1
1 2142

"dan" <da******@aol.com> wrote in message
news:b0**************************@posting.google.c om...
I need help in figuring out what to do for this program, it is a
program that reads book id, unit price, book purchased, book sold,
book returned, and city(respectively). It is a control break program
that prints a report for each city on a separate screen with a total,
then at the end it has a grand total. It prints to the screen and an
output file.
Input file looks like (the char is the city)
200 1.40 30 13 1 B
201 7.50 13 1 0 B
202 2.50 50 23 3 B
198 5.00 45 15 2 C
200 1.40 13 2 0 C
201 7.85 15 5 0 N
202 2.25 50 30 1 N
155 3.50 11 5 1 P

sample output

[SNIP]

Just some hints. You should think of a way to organize your data internally.
First, create a class that will store the information of one record. Then
you could for example use a multimap with the key being the city code and
the value being an object of your record class. After reading one line you
just add a new element to your multimap. In the end you've got a multimap
full of records which you just have to process accordingly. Of course there
are different, more sophisticated ways to organize your data but for this
simple thing the multimap might be sufficient. After the whole file has been
read you just go ahead creating the summary for all records sharing the same
key and you're done.

HTH
Chris
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
2
by: stanlo | last post by:
Hallo to everyone, i am just begining to learn c++ even though i did pascal when i studied mathematics in the univesity.i just took on my self a project which writing a c++ program which does...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
12
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: ashishbathini | last post by:
Hi guys here is my problem ... this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me .... but my problem is ... i hav a freq comonent in it .......
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.