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(respective ly). 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(istre am& 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.tx t");
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(io s::fixed);
outfile.setf(io s::showpoint);
outfile.precisi on(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(infil e, 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(istre am& 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 1 2157
"dan" <da******@aol.c om> wrote in message
news:b0******** *************** ***@posting.goo gle.com... 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(respective ly). 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 my
server program written in python it simply hangs.it does not show any
error also.I've tried sample programs available .I don understand what
the reason is as i am quite new to it.
here is teh server side program:
///////////////////////
|
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 addition,
subtraction, multiplication and division.Highest number of input
characters should be 80 and the program should output eror meseges
like, when division by zero is done,or catch wrong user inputs like
letters of the alphabet.Please i have...
|
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 I
believe if it's solved, the remaining stuff is easy...
my full program until now is here:
http://www.geocities.com/tom4_h4wk/progmail.zip
the problem is the segmentation fault when main trys to run
leficheiro.c.... the *.c2 files are the...
|
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 NFA has initial states: 2 and 12
ending states 2 and 12
I need help to switch program below from FSA to recognize NFA. I was
trying to do a general program so if i have another expression it can
be easily changed thus no...
|
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 occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of occurences.
The second is to let you enter a word, with the program reporting how
many times the...
| |
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 we
enter 4, the size of four triangles are 4 rows.
In addition, I am also writing a program which i started and failed in
giving the right size of traingles. I will appreciate if somebody can
help.
|
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 run, However, i
simply created this program in arrays and it runs good except i cant
figure out how to compute the standard deviation. The coding is below.
Any help will be appreciated.
1) The Program will prompt the user for six grades to be...
|
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 .... what I have to do with it is ... I need to take the output of the second program (which is the freq component ) and this Shud be the input for the program A
i am not sure bout the freq component too ....since i am unable to understand the program...
|
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 directory. Assume that all contents of all the files may be
held in memory at the same time. Do not use unsafe code blocks and/
or pointers.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |