【发布时间】:2014-10-19 16:58:11
【问题描述】:
所以我正在做这个项目,要求用户根据需要在系统中输入几乎尽可能多的客户。他们应该输入客户姓名、电影、每件商品的数量和成本。稍后它应该提供总和、平均值等(平均值等我还没有实现)。
更新:
我已经修复了我的字符串,但我认为我的打印数组有问题。不完全确定如何将我的名字变成一个字符串,这样我就可以保留 Alyssa 和 Dave 错误只是一堆数字,只是继续下去:
程序正在运行
Welcome to our storing system for your account information
If you wish to begin inputting information, Please enter 1 for Yes and 2 for No
1
Enter customer's first name:
Alyssa
To choose which Motion Picture that you purchased a DVD under:
Enter 1 for Paramount. Enter 2 for Twentieth Century Fox.
Enter 3 for Warner and 4 for WaterFront
Input the data in the following format.
Motion Picture Number <space> Amount of motion pictures purchased <space> Cost of movies
Enter -1 <space> 0 <space> 0 <space> to end
1 2 20
Enter Motion Picture <space> Amount purchased <space> Cost of movies
2 33 201
Enter Motion Picture <space> Amount purchased <space> Cost of movies
-1 0 0
Still have more employees? Enter 1 to add them or 2 to end
1
Enter customer's first name:
Dave
To choose which Motion Picture that you purchased a DVD under:
Enter 1 for Paramount. Enter 2 for Twentieth Century Fox.
Enter 3 for Warner and 4 for WaterFront
Input the data in the following format.
Motion Picture Number <space> Amount of motion pictures purchased <space> Cost of movies
Enter -1 <space> 0 <space> 0 <space> to end
1 4 20
Enter Motion Picture <space> Amount purchased <space> Cost of movies
-1 0 0
Still have more employees? Enter 1 to add them or 2 to end
2
错误
下面列出的是您在每个电影公司中的总数
客户名称派拉蒙二十世纪福克斯华纳海滨 戴夫0 戴夫20 戴夫0 戴夫20 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0 戴夫0戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫 0 戴夫
我想要的印刷品:**
Customer Name Paramount Twentieth Century Fox Warner WaterFront Total
Alyssa 2 4 0 0 80
Dave 3 0 0 0 66.00
**
等等
MotionPicture.h
#ifndef MOTIONPICTURE_H
#define MOTIONPICTURE_H
#include <cstring>
using namespace std;
class motionPicture {
public:
motionPicture();
void getData();
static const int rows = 6;
static const int columns = 100;
void printArray();
void getName();
void setName();
private:
int company;
double table[rows][columns];
string name;
};
#endif
MotionPicture.cpp
#include <iostream>
#include "motionPicture.h"
#include <iomanip> //to use setw
#include <cstring>
#include <string>
using namespace std;
motionPicture :: motionPicture() {
//initalize the table
for (int i =0; i < rows; i++){
for (int j=0; j<columns; j++){
table[i][j] =0;
}//end j for loop
}//end i for loop
}//end constructor
void motionPicture :: setName(){
cout<<"Enter customer's first name: " <<endl;
cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
getline(cin, name);
}//end setName
void motionPicture :: getName() {
cout<< name;
//}//end getName
void motionPicture:: getData() {
int system;
int motion, quanity;
double cost;
cout <<"If you wish to begin inputting information, Please enter 1 for Yes and 2 for No"<<en$
cin >> system;
while (system !=2)
{
setName();
//getName();
cout <<"To choose which Motion Picture that you purchased a DVD under:"<<endl;
cout <<"Enter 1 for Paramount. Enter 2 for Twentieth Century Fox."<<endl;
cout <<"Enter 3 for Warner and 4 for WaterFront"<<endl<<endl;
cout <<"Input the data in the following format."<<endl;
cout <<"Motion Picture Number <space> Amount of motion pictures purchased <space> Cost of m$
cout <<"Enter -1 <space> 0 <space> 0 <space> to end"<<endl<<endl;
cin >> motion >> quanity >> cost;
while (motion != -1) {
table[motion-1][quanity-1] +=cost;
cout <<"Enter Motion Picture <space> Amount purchased <space> Cost of movies$
cin >> motion>> quanity >>cost;
}//end cost while
cout<<"Still have more employees? Enter 1 to add them or 2 to end" <<endl<<endl;
cin >>system;
}//end system while
}//end getData
void motionPicture :: printArray() {
cout <<"Listed below is your totals within each Motion Picture Company"<<endl;
cout <<"----------------------------------------------------------------"<<endl;
cout<<"Customer Name" <<setw(15) << "Paramount" <<setw(11) << "Twentieth Century Fox"
<< setw(23)<<"Warner" <<setw(8) <<"WaterFront" << setw(12)<<endl;
for (int i= 0; i <rows; i++){
//for(int j=0; j<100; j++){
double total =0;
// begin to print the table
for (int j=0; j<columns; j++) {
getData();
cout table[i][j] << " ";
//input total
total += table[i][j];
}//end j loop
cout <<total<<"\n";
}//end i loop
}//end print
motionRun.cpp
#include <iostream>
#include "motionPicture.h"
using namespace std;
int main () {
cout << "Welcome to our storing system for your account information"
<<endl;
motionPicture objMotion;
objMotion.getData();
objMotion.printArray();
return 0;
}
【问题讨论】:
-
编译器已经说明出了什么问题,在哪个文件中,在哪一行
-
我知道错误的位置。我不熟悉错误的含义。
标签: c++ arrays string printing