【发布时间】:2019-07-18 11:34:02
【问题描述】:
我有一个学校作业,我必须在其中创建一个葡萄酒库存系统,用户可以在其中添加多种不同的葡萄酒,我假设没有有限的数量。
我需要创建向量,但我不确定。我不知道该尝试什么。
#include <string>
#include <iostream>
#include <vector>
using namespace std;
struct Wine1
{ //struct for Wine pssibly needs Vector
string name;
string year;
string place;
string price;
} wine;
void printwine(Wine1 wine);
int main()
{
string str; //input for data
cout << "Please enter the data of the First wine: " << endl;
cout << "Enter name: ";
getline(cin, wine.name);
cout << endl << "Enter year: ";
getline(cin, wine.year);
cout << endl << "enter country of creation: ";
getline(cin, wine.place);
cout << endl << "enter price: ";
getline(cin, wine.price);
cout << endl;
cout << "your entered data: " << endl;
printwine(wine);
cout << endl;
printwine2(wine2);
cout << endl;
printwine3(wine3);
}
void printwine(Wine1 wine)
{ //data the user typed as output
cout << "Wine1" << endl;
cout << "the name is: " << wine.name << endl;
cout << "it's year is: " << wine.year << endl;;
cout << "its country of creation is: " << wine.place << endl;;
cout << "it's price is: " << wine.price << endl;
}
它应该为添加的每种葡萄酒输出葡萄酒的名称、年份、国家和价格。
【问题讨论】:
-
std::vector<struct Wine1>可能是您需要的。 -
对不起,如果这是一个愚蠢的问题,必须把这个放在哪里?
标签: c++ class c++11 data-structures stdvector