所以我仍在解决这个问题,并认为我的做法是正确的。但是,现在它只显示“ABC Industries”和“Report”,而不是仅在未输入信息时才显示。我在哪里弄乱了我的代码?
//This program displays a company's name and report.
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
class Heading {
private:
string company;
string report;
public:
Heading() {
company = "ABC Industries";
report = "Report";
}
Heading(string c, string r) {
company = c;
report = r;
}
void storeInfo(string company, string report);
string getCompany() {
return company;
}
string getReport() {
return report;
}
};
void Heading::storeInfo(string c, string r) {
c = company;
r = report;
}
void storeInfo(Heading&);
void showInfo(HANDLE, Heading);
void placeCursor(HANDLE, Heading);
int main() {
Heading company;
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
storeInfo(company);
showInfo(screen, company);
cin.ignore();
cin.get();
return 0;
}
/*****storeInfo*****/
void storeInfo(Heading &item) {
string company;
string report;
cout << "\nPlease enter the company name.\n";
getline(cin, company);
cout << "\nPlease enter the report name.\n";
\
getline(cin, report);
item.storeInfo(company, report);
}
/*****placeCursor*****/
void placeCursor(HANDLE screen, int row, int col) {
COORD position;
position.Y = row;
position.X = col;
SetConsoleCursorPosition(screen, position);
}
/*****showInfo*****/
void showInfo(HANDLE screen, Heading item) {
system("cls");
placeCursor(screen, 6, 25);
cout << "********************************" << endl;
placeCursor(screen, 8, 32);
cout << item.getCompany() << endl;
placeCursor(screen, 11, 36);
cout << item.getReport();
placeCursor(screen, 13, 25);
cout << "********************************" << endl;
}