i know this is a simple problem solving but i'm still cannot figure it out. i'm trying to print out the input into an array by calling the function but its not working. Help me. below down here is the code. main.cpp and groovy.h. for your information, i am new to programming
Here is the output that i get
//main.cpp
#include <iostream>
#include "groovy.h"
#include <string>
#include <iomanip>
using namespace std;
void displayInventory(const groovy[], int);
int main() {
int s;
const int size = 20;
groovy car[size];
/*= {
groovy("M01", "Mazda CX5", 132403.00),
groovy("M02", "Mazda CX3", 126829.00),
groovy("M03", "Mazda 6 Grand Touring", 208408.00),
groovy("M04", "Mazda CX8", 173038.00),
};
cout<<"
List of available car :
"<<endl;
displayInventory(car, size);
*/
string code, model;
double price;
cout<<"
Please enter model details :- "<<endl;
cout<<"Model code : ";
cin>>code;
cout<<"Model name : ";
cin>>model;
cout<<"Model price : ";
cin>>price;
car[size].storeInfo(code, model, price);
displayInventory(car, size);
return 0;
}
void displayInventory(const groovy object[], int size){
for (int i = 0; i < size; i++){
cout<<setw(5)<<left<<object[i].getCode()
<<setw(28)<<left<<object[i].getModel()
<<"RM "<<right<<object[i].getPrice()<<endl;
}
}
//groovy.h
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class groovy{
private:
string modelCode;
string model;
double price;
public:
groovy(){
modelCode = "XXX";
model = " ";
price = 0.0;
}
groovy(string c,string m, double p){
modelCode = c;
model = m;
price = p;
}
void storeInfo(string c,string m, double p) {
modelCode = c;
model = m;
price = p;
}
string getCode() const {
string code = modelCode;
return code;
}
string getModel() const {
string m = model;
return m;
}
double getPrice() const {
double p = price;
return price;
}
};
question from:
https://stackoverflow.com/questions/65649720/print-out-the-input-into-an-array-by-calling-the-function-but-its-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…