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

C++ Help...Asignment due tomorrow...Friday!!!

I have an assignment and I just and stuck and do not know where to start. The assignment is as follows:
____________________________________________

Write a C++ program that reads a file that holds certain stock information. The input data file looks something like:

**(the text file has 10 companies, each with abbreviaition and w/ 7 stock prices for each)**

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
Feb 1 '07 #1
10 1479
Here is my failed attempt: I was frustrated b/c I counld not get the file to input so I manually typed everything in!



Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     ifstream inFile;
  14.     inFile.open("stock_data.txt");
  15.     if (inFile.fail())
  16.     {
  17.         cout << "Input file open failed.\n";
  18.         cout << "Call for help.\n";
  19.         exit (0);
  20.     }
  21.  
  22. const int NUM_ROWS = 10;
  23. const int NUM_COLS = 2;
  24. const int NUM_COLSS = 7;
  25. string company[NUM_ROWS][NUM_COLS] = {"International Business Machines", "IBM", "Earth Bio Fuels dba Bio-Willie", "EBF", 
  26.                                     "Hewlett-Packard Corporation, HPQ", "Harley-Davidson Inc.", "HOG", 
  27.                                     "Apple Computer Inc., APL", {J.C. Penney Company, JCP}, {Wal-Mart Stores, WMT},
  28.                                     {Exxon-Mobil Corporation, XOM}, {McDonalds Food Stores, MCD}, {Dell Computer, DEL}}; 
  29.  
  30.     int quotes[NUM_ROWS][NUM_COLSS] = {{99.54, 97.11, 97.24, 98.45, 99.01, 99.20, 100.65}, 
  31.                         {6.49, 5.98, 5.34, 2.87, 2.32, 1.87, 0.68}, 
  32.                         {42.02, 42.05, 42.34, 42.56, 39.88, 41.54, 43.60}, 
  33.                         {71.62, 70.67, 71.98, 72.25, 71.15, 72.22, 72.23}, 
  34.                         {86.79, 84.33, 82.89, 89.82, 91.32, 85.43, 86.78}, 
  35.                         {82.21, 83.56, 81.87, 70.21, 82.54, 83.21, 81.09}, 
  36.                         {47.96, 47.99, 48.04, 48.67, 49.21, 48.34, 49.87}, 
  37.                         {72.90, 73.01, 73.90, 75.32, 76.10, 79.87, 80.87}, 
  38.                         {44.34, 43.43, 42.98, 44.91, 45.23, 44.01, 43.87}, 
  39.                         {24.49, 23.87, 23.16, 21.67, 22.90, 22.34, 21.76}};
  40.  
  41.  
  42.  
  43.  
  44.     cout << "This program displays the stock information for 10 companies.\n";
  45.     cout << "Company  ID   Monday  Tuesday  Wednesday  Thursday  Friday  Saturday  Sunday  Average.\n";   
  46.  
  47. for (int count = 0; count < NUM_ROWS; count++)
  48. {
  49.     cout << company[count] << endl;
  50.     cout << quotes[count] << endl;
  51. }
  52. return 0;
  53. }
Feb 1 '07 #2
dav3
94
Here is my failed attempt: I was frustrated b/c I counld not get the file to input so I manually typed everything in!



#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);
}

const int NUM_ROWS = 10;
const int NUM_COLS = 2;
const int NUM_COLSS = 7;
string company[NUM_ROWS][NUM_COLS] = {"International Business Machines", "IBM", "Earth Bio Fuels dba Bio-Willie", "EBF",
"Hewlett-Packard Corporation, HPQ", "Harley-Davidson Inc.", "HOG",
"Apple Computer Inc., APL", {J.C. Penney Company, JCP}, {Wal-Mart Stores, WMT},
{Exxon-Mobil Corporation, XOM}, {McDonalds Food Stores, MCD}, {Dell Computer, DEL}};

int quotes[NUM_ROWS][NUM_COLSS] = {{99.54, 97.11, 97.24, 98.45, 99.01, 99.20, 100.65},
{6.49, 5.98, 5.34, 2.87, 2.32, 1.87, 0.68},
{42.02, 42.05, 42.34, 42.56, 39.88, 41.54, 43.60},
{71.62, 70.67, 71.98, 72.25, 71.15, 72.22, 72.23},
{86.79, 84.33, 82.89, 89.82, 91.32, 85.43, 86.78},
{82.21, 83.56, 81.87, 70.21, 82.54, 83.21, 81.09},
{47.96, 47.99, 48.04, 48.67, 49.21, 48.34, 49.87},
{72.90, 73.01, 73.90, 75.32, 76.10, 79.87, 80.87},
{44.34, 43.43, 42.98, 44.91, 45.23, 44.01, 43.87},
{24.49, 23.87, 23.16, 21.67, 22.90, 22.34, 21.76}};




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 count = 0; count < NUM_ROWS; count++)
{
cout << company[count] << endl;
cout << quotes[count] << endl;
}
return 0;
}
I dont believe your doing anything with the file that your reading in?? It looks like you just have a statement saying what happens if it cant be read.
Feb 1 '07 #3
I guess that is where I get frustrated...I do not know how to make the file read out like it is suppose to. I know I have to set up the arrays and make so loops but ????
Feb 1 '07 #4
Ganon11
3,652 Expert 2GB
Well, you know the file is written in the format

Full Name
3-Letter Abbrev
Value1
Value2
Value3
Value4
Value5
Value6
Value7

So, in a loop (until end of file), first get the full name and store it into a string, then store that string in company[i][0], where i is the number of times the loop has been executed. Then get the abbreviation and store it in company[i][1]. Next, in a second loop, get each of the 7 values and store them in quotes[i][j], where j is the number of values you have read.
Feb 1 '07 #5
This was my other attempt:

#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 company[10][2] = {""};
int quotes[10][7] = {0.0};


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

for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 2; j++)
{
cout << company[i][j] << endl
}
}
return 0;
}

--------------------------------------------------------------------------------
Feb 1 '07 #6
Well, you know the file is written in the format

Full Name
3-Letter Abbrev
Value1
Value2
Value3
Value4
Value5
Value6
Value7

So, in a loop (until end of file), first get the full name and store it into a string, then store that string in company[i][0], where i is the number of times the loop has been executed. Then get the abbreviation and store it in company[i][1]. Next, in a second loop, get each of the 7 values and store them in quotes[i][j], where j is the number of values you have read.




***What does that look like in code?***
Feb 1 '07 #7
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. int i = 0; // 0 companies have been read
  2. while (!inFile.eof()) { // While there is still data to read
  3.    string compName, compAbbrev;
  4.    // Get company name and abbrev from inFile
  5.    company[i][0] = compName;
  6.    company[i][1] = compAbbrev;
  7.    for (int j = 0; j < 7; j++) {
  8.       float price;
  9.       // Get the float value from inFIle
  10.       stocks[i][j] = price;
  11.    }
  12.    i++; // Increment the number of companies read so far
  13. }
Feb 1 '07 #8
Expand|Select|Wrap|Line Numbers
  1. int i = 0; // 0 companies have been read
  2. while (!inFile.eof()) { // While there is still data to read
  3.    string compName, compAbbrev;
  4.    // Get company name and abbrev from inFile
  5.    company[i][0] = compName;
  6.    company[i][1] = compAbbrev;
  7.    for (int j = 0; j < 7; j++) {
  8.       float price;
  9.       // Get the float value from inFIle
  10.       stocks[i][j] = price;
  11.    }
  12.    i++; // Increment the number of companies read so far
  13. }









THANK YOU FOR YOUR HELP....I WILL TRY IT AND LET YOU KNOW! :)
Feb 1 '07 #9
So now what do I cout << ? (Here is the updated version)

:
#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;
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 <<
// Get the float value from inFile

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

return 0;
}
Feb 1 '07 #10
Need last minute help with this program......Can someone code this darn thing for me in the mext hour??????? I have PayPal....:)
Feb 2 '07 #11

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

Similar topics

3
by: Jake | last post by:
OK Ive got a huge amount of If Then statements that Im sure can be stripped way down to a simple loop or two but Im not familiar enough with them to know where to start. Basically this is a truck...
4
by: manning_news | last post by:
I've got the following query in SQL 2000: select a.SSN, a.MonthName, a.IMClinicDay, b.IMClinicDay as SecondDay from tblResidentRotations a inner join view7 b on a.SSN = b.SSN where...
19
by: Fran?ois Laroche | last post by:
hey guys, I know that you will tell me that's easier to do in php or even in asp, but I just dont have the time to learn it 1- I need a javascript that will show the date of tomorrow 2- I need a...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
2
by: Dennis Schulz | last post by:
Hi all, the following programm is supposed to check for login and password with inbuilt linux functions. in line 57 and 64 there are erorrs: incompatible types in asignment. whats wrong with...
5
by: vj | last post by:
I'm doing: a = now() delta = ReltaiveDateTime(days=+6, weekday(mx.DateTime.Friday, 0)) Next Friday: a+delta a: march 23 a+delta: Gives me March 31st and not March 24th Any ideas?
2
by: Maximus | last post by:
I need some help. I have an .asp page that interfaces with an Access table (wjs_SuperInput). The .asp page looks to the table and pulls a recordset based on a job number, 12345, and a weekending...
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.