473,385 Members | 1,829 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,385 software developers and data experts.

Admitting defeat...Will pay small fee $ for small program

I have an assignment that is due tomorrow (Friday). The details are as follows:
.................................................. .................................................. ............
Write a C++ program that reads a file that holds certain stock information. The input data file looks something like:

International Business Machines
IBM
35.67
36.79
39.66
32.09
31.67
31.67
34.76
Epson Manufacturing Corporation
EPS
31.99
28.87
24.60
29.65
31.33
32.67
34.08
Company Name
3-letter stock exchange ID
Value for Sunday
Value for Monday
Value for Tuesday
Value for Wednesday
Value for Thursday
Value for Friday
Value for Saturday

The file will have no more than 10 records.

You will need to store the data in two separate (parallel) arrays. Store the company names and IDs in a 2-d array of type string. Store the values in a 2-d array of type float. That is, the string array should have dimensions [10][2] so it will have 10 rows and 2 columns numbered 0,1,2,3,4,5,6,7,8,9 and 0,1 respectively. The numeric array should have dimensions of [10][7] so it will have 10 rows and 7 columns, numbered 0,1,2,3,4,5,6,7,8,9 and 0,1,2,3,4,5,6 respectively.

Phase 1:
Your program should compute the 7-day average for each company’s stock and also the day’s total sum of values for each day. Use manipulators so your output is neat and lined up correctly. An example of your preliminary report follows:

Company ID Closing Price
----------------------------------------------------------
International Business Machines IBM 34.56
Epson Manufacturing Co. EPS 42.36
. . . . . . . . . . . . ... .....
Company Name XXX 99.99
----------------------------------------------------------
Total 999.99
.................................................. .................................................. .........

THIS IS THE CODE I HAVE SO FAR..........SEE BELOW.

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;





int main()
{
ifstream inFile;
inFile.open("stock_data.txt");
if (inFile.fail())
{
cout << "Input file open failed.\n";
cout << "Call for help.\n";
exit (0);
}

string compName, compAbbrev;
string company[i][0] = compName;
int quotes[i][1] = compAbbrev;
stocks[i][j] = price;

cout << "This program displays the stock information for 10 companies.\n";
cout << "Company ID Monday Tuesday Wednesday Thursday Friday Saturday Sunday Average.\n";

for (int j = 0; j < 7; j++)
{
float price;
cout << company[i][0] << endl;
// Get the float value from inFile

}
i++; // Increment the number of companies read so far

return 0;
}

.................................................. .................................................. ...........
THE TEXT FILE IS CALLED stock_data.txt and I will copy and paste it below.

International Business Machines
IBM
99.54
97.11
97.24
98.45
99.01
99.20
100.65
Earth Bio Fuels, dba Bio-Willie
EBF
6.49
5.98
5.34
2.87
2.32
1.87
0.68
Hewlett-Packard Corporation
HPQ
42.02
42.05
42.34
42.56
39.88
41.54
43.60
Harley-Davidson, Inc.
HOG
71.62
70.67
71.98
72.25
71.15
72.22
72.23
Apple Computer, Inc.
APL
86.79
84.33
82.89
89.82
91.32
85.43
86.78
J.C. Penney Company
JCP
82.21
83.56
81.87
70.21
82.54
83.21
81.09
Wal-Mart Stores
WMT
47.96
47.99
48.04
48.67
49.21
48.34
49.87
Exxon-Mobil Corporation
XOM
72.90
73.01
73.90
75.32
76.10
79.87
80.87
McDonalds Food Stores
MCD
44.34
43.43
42.98
44.91
45.23
44.01
43.87
Dell Computer
DEL
24.49
23.87
23.16
21.67
22.90
22.34
21.76
Feb 2 '07 #1
7 1433
nmadct
83 Expert
Well, looks like this program has taught you an important lesson in computer programming. Don't start the day before it's due.
Feb 2 '07 #2
I start off and on a few days ago....I barely have any hair left!
Feb 2 '07 #3
nmadct
83 Expert
I used to have the same problem with writing papers, no matter when I tried to start I didn't get anything accomplished until just before they were due. That's why I switched to computer programming.

Luckily, there's still lots of hours left.

You need a loop like the one Ganon1 showed you in the other thread. Your code here doesn't loop over the input values so it could only read one company's info.

What you need to do is:

1. Read in the company info. This is where that loop comes in. This will fill up the arrays that the assignment describes. The loop counter variable also keeps a count of how many companies you have, this is important because you'll need it for the next step.
2. Make another numeric array with 7 values. These are for the overall daily totals. Set every value in this array to 0.
3. In another loop, do the calculations for each company. Loop over all 7 daily values (in your stocks array), adding them up (you need an accumulator variable to hold the total), then divide the total by 7, that's your average. While you're going through these values, add each one to the proper overall daily total.
4. Now you've got all the values you were supposed to compute, just start printing them out.

Also, please note in the "Reply Guidelines" (at right when you're typing your reply) how you can format your code so it keeps its indentation on the web page.

Good luck!
Feb 2 '07 #4
I used to have the same problem with writing papers, no matter when I tried to start I didn't get anything accomplished until just before they were due. That's why I switched to computer programming.

Luckily, there's still lots of hours left.

You need a loop like the one Ganon1 showed you in the other thread. Your code here doesn't loop over the input values so it could only read one company's info.

What you need to do is:

1. Read in the company info. This is where that loop comes in. This will fill up the arrays that the assignment describes. The loop counter variable also keeps a count of how many companies you have, this is important because you'll need it for the next step.
2. Make another numeric array with 7 values. These are for the overall daily totals. Set every value in this array to 0.
3. In another loop, do the calculations for each company. Loop over all 7 daily values (in your stocks array), adding them up (you need an accumulator variable to hold the total), then divide the total by 7, that's your average. While you're going through these values, add each one to the proper overall daily total.
4. Now you've got all the values you were supposed to compute, just start printing them out.

Also, please note in the "Reply Guidelines" (at right when you're typing your reply) how you can format your code so it keeps its indentation on the web page.

Good luck!





i UNDERSTAND THEM IN ENGLISH BUT GET LOST IN ALL THE CODING....I would like someone to help with the coding...Please.....
Feb 2 '07 #5
nmadct
83 Expert
i UNDERSTAND THEM IN ENGLISH BUT GET LOST IN ALL THE CODING....I would like someone to help with the coding...Please.....
This is a help forum, not a C++ tutorial. I suggest you do a Google search for "c++ tutorial" instead.

It is also not a place for you to get ready-made solutions to your homework assignments.
Feb 2 '07 #6
Ganon11
3,652 Expert 2GB
Indeed. Our policy is that giving you completed code is the equivalent of cheating - especially when you explicitly tell us that this is a homework assignment. Now, we have given you a great deal of advice - it is your job to understand what we are saying and finish the project yourself.
Feb 2 '07 #7
RedSon
5,000 Expert 4TB
Well I dont know about a small fee, but my consulting fee is $70 USD per hour of work with a minimum fee of $210, if the work can be completed quickly. I also charge a premium based on the complexity of the solution and how many different classes are needed. Extra if the solution must be recursive. If you are interested in hireing my services then you obviously have enough money to not need a degree in computer science.
Feb 2 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
4
by: Robert Bralic | last post by:
Hi, Can anybody send to me aby small c++ program that is compilable vith gpp under Linux ,that I can belive that C++ realy exists ,(1000-2000) lines program source. robert.bralic@si.htnet.hr
29
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
12
by: elty123 | last post by:
I have a small C# program (about 400 lines of code) that is only 28kb after compiled. However when it runs (takes a whole 5 seconds) it takes up nearly 20MB of memory and I don't see why. ...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
10
by: apparker | last post by:
I'm creating a new GUI for a program and it is for a medical exam. There are so many different things to ask someone during a history it wastes too much space to make checkboxes for everything so I...
4
by: driplet | last post by:
Hi there: I made a very samll windows application program in C++. I found my computer becomes very slow after this program loaded. I checked windows task manager and found this small program takes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.