C ++帮助......明天到期......周五!!! [英] C++ Help...Asignment due tomorrow...Friday!!!

查看:62
本文介绍了C ++帮助......明天到期......周五!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项任务,我只是坚持,不知道从哪里开始。作业如下:

____________________________________________

编写一个C ++程序,读取包含某些股票信息的文件。输入数据文件类似于:


**(文本文件有10个公司,每个公司都有abbreviaition,每个都有7个股票价格)**


国际商业机器

IBM

35.67

36.79

39.66

32.09

31.67

31.67

34.76

爱普生制造公司

EPS

31.99

28.87

24.60

29.65

31.33

32.67

34.08

公司名称

3个字母的证券交易所ID

周日价值

周一价值

周二价值

周三价值

周四价值

周五价值

周六价值


文件不超过10条记录。


你将需要将数据存储在两个单独的(并行)数组中。将公司名称和ID存储在类型为字符串的二维数组中。将值存储在float类型的二维数组中。也就是说,字符串数组应该有维度[10] [2],因此它将分别有10行和2列,分别编号为0,1,2,3,4,5,6,7,8,9和0,1。数值数组的尺寸应为[10] [7],因此它将有10行7列,编号为0,1,2,3,4,5,6,7,8,9和0,1,2,分别为3,4,5,6。


阶段1:

您的程序应计算每家公司股票的7天平均值以及每天的总和值。使用操纵器,使输出整齐,排列正确。您的初步报告的示例如下:


公司ID收盘价

------------------ ----------------------------------------

国际商务机器IBM 34.56

爱普生制造有限公司EPS 42.36

。 。 。 。 。 。 。 。 。 。 。 。 ...... .....

公司名称XXX 99.99

---------------------- ------------------------------------

总计999.99

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

推荐答案

这是我失败的尝试:我很沮丧b / c我没有得到文件输入所以我手动输入所有内容!



Here is my failed attempt: I was frustrated b/c I counld not get the file to input so I manually typed everything in!



展开 | 选择 | Wrap | 行号



这是我失败的尝试:我很沮丧b / c我没有得到文件输入所以我手动输入所有内容!



#include< ; iostream>

#include< string>

#include< fstream>

#include< iomanip>

使用命名空间std;




int main()

{

ifstream inFile;

inFile.open(" stock_data.txt");

if(inFile.fail())

{

cout<< 输入文件打开失败。\ nn;

cout<< 请求帮助。\ n;

退出(0);

}


const int NUM_ROWS = 10 ;

const int NUM_COLS = 2;

const int NUM_COLSS = 7;

字符串公司[NUM_ROWS] [NUM_COLS] = {"国际商业机器,IBM,Earth Bio Fuels dba Bio-Willie,EBF,

Hewlett-Packard Corporation,HPQ,Harley-Davidson Inc. "," HOG",

" Apple Computer Inc.,APL",{JC Penney Company,JCP},{Wal-Mart Stores,WMT},

{Exxon-Mobil Corporation,XOM},{McDonalds Food Stores,MCD},{Dell Computer,DEL}};


int引号[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<< 此程序显示10家公司的股票信息。\ n;

cout<< 公司ID周一周二周三周四周五周六周日Average.\ n;


for(int count = 0; count< NUM_ROWS; count ++)

{

cout<<公司[count]<< endl;

cout<<引号[count]<<结束;

}

返回0;

}
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.


我想这就是我感到沮丧的地方......我不知道如何将文件读出来喜欢它。我知道我必须设置数组并进行循环但是????
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 ????


这篇关于C ++帮助......明天到期......周五!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆