I am trying to get this program to work using a for loop. My problem is that the cin >> inside the for loop says that "no operator matches these operands" .
I would like to use a for loop for all the setter functions that I have in the main function . One more question is how to relate the information that I get from my setter function to the displayCars user defined function defined outside of class.
This is the code :
#include<iostream>
#include<ctime>
#include<string>
#include<iomanip>
using namespace std;
class car
{
private:
string carInformation;
string manufacturer;
string model;
string type;
double price;
int serialNo;
int warranty;
double rebate;
public:
car();
car (string Info_manufacturer,string Info_model,string Info_type, double Info_price,int Info_serialNo,int Info_warranty,double Info_rebate); //constructor
//member function prototypes
//void print();
cout<< " This pogram takes in information about your car and displays it on the screen. Below is an example that has the details of car1. You will have to input the \n data to fill in the information about car2.\n\n\n\n";
cout<<endl<<endl<<endl;
car c [2] ;
for ( int i = 0 ; i <= 2 ; i++)
{
cin >> c[0].setmanufacturer (input_manufacturer);
}
cout << " Press on any key to look at the information \n\n\n\n\n\n\n\n";
system("pause");
system("cls");
c[0].displaycars();
c[1].displaycars();
//car1.print();
//car2.print();
//member function definitions
/*
void car :: print()
{
cout << carInformation;
}
*/
void car :: setmanufacturer(string Info_manufacturer)
{
cout << " Please enter the information for Manufacturer : " ;
cin >> Info_manufacturer;
cout<<endl<<endl;
manufacturer = Info_manufacturer;
}
void car :: settype(string Info_type)
{
cout << " Please enter the information for Type : " ;
cin>>Info_type;
cout<<endl<<endl;
type = Info_type;
}
void car :: setmodel(string Info_model)
{
cout << " Please enter the information for Model : " ;
cin >>Info_model;
cout<<endl<<endl;
model = Info_model;
}
void car :: setprice(double Info_price)
{
cout << " Please enter the information for Price : " ;
cin>>Info_price;
cout<<endl<<endl;
price = Info_price;
}
void car :: setserialNo(int Info_serialNo)
{
cout << " Please enter the information for Serial Number : " ;
cin>>Info_serialNo;
cout<<endl<<endl;
serialNo = Info_serialNo;
}
void car :: setwarranty(int Info_warranty)
{
cout << " Please enter the information for Warranty : " ;
cin >>Info_warranty;
cout<<endl<<endl;
warranty = Info_warranty;
}
void car :: setrebate(double Info_rebate)
{
cout << " Please enter the information for Rebate : " ;
cin >> Info_rebate;
cout<<endl<<endl;
rebate = Info_rebate;
}
string car :: getmanufacturer()
{
return manufacturer;
}
string car :: getmodel()
{
return model;
}
string car :: gettype()
{
return type;
}
double car :: getprice()
{
return price;
}
int car :: getserialNo()
{
return serialNo;
}
int car :: getwarranty()
{
return warranty;
}
double car :: getrebate()
{
return rebate;
}
void car :: displaycars()
{
car c[2];;
cout<<" Information from funtion prototype inside of class"<<endl<<endl;
cout << " \t\t\t\tCAR " <<endl<<endl;
cout <<endl<<endl<< " Manufacturer : \t\t" << manufacturer <<endl<<endl;
cout<< " Model : \t\t\t"<<model<<endl<<endl;
cout<<" Type : \t\t\t" << type<<endl<<endl;
cout << " Price ($): \t\t\t" <<price<<endl<<endl;
cout<<" Serial Number : \t\t" << serialNo<<endl<<endl;
cout <<" Warranty (yrs) : \t\t" <<warranty<<endl<<endl;
cout << " Rebate (%) : \t\t\t"<< rebate<<endl<<endl;
}
void displaycars(string manufacturer,string model,string type,double price, int serialNo, int warranty, double rebate)
{
car c[2];
cout<<" Information from funtion prototype outside of class"<<endl<<endl;
cout << " \t\t\tCAR 1 \t\t CAR 2 " <<endl<<endl;
cout <<endl<<endl<< " Manufacturer : \t\t" <<manufacturer << "\t\t"<<manufacturer <<endl<<endl;
cout<< " Model : \t\t\t"<<model<<"\t\t"<<model<<endl<<endl;
cout<<" Type : \t\t\t" << type<<"\t\t"<<type<<endl<<endl;
cout << " Price ($): \t\t\t" <<price<<"\t\t"<<price<<endl<<endl;
cout<<" Serial Number : \t\t" << serialNo<< "\t\t" <<serialNo<<endl<<endl;
cout <<" Warranty (yrs) : \t\t" << warranty<< "\t\t" << warranty<<endl<<endl;
cout << " Rebate (%) : \t\t\t"<< rebate<<"\t\t"<< rebate<<endl<<endl;
My problem is that the cin >> inside the for loop says that "no operator matches these operands" .
If you are using the shift operator on cin, you need to provide a variable which is either a data type or a string.
The following should do nicely:
1 2 3 4 5 6
for ( int i = 0 ; i <= 2 ; i++)
{
string input_manufacturer;
cin >> input_manufacturer;
c[0].setmanufacturer (input_manufacturer);
}
how to relate the information that I get from my setter function to the displayCars user defined function defined outside of class.
Get all your values using the get- functions for your car class and then call displayCars with all the values. Personally, I would have just written a displayCars member function and called it for each car in your array.
Yes I have done that , but the assignment requires me to define a user defined member function outside of class and then display the information which is being displayed by the member function inside the class. I am not sure how to do that.
So the last function definition where I am defining the displaycars with all the arguments , I am basically displaying the information about those arguments from int main where I have defined those variables , but I need to get the information that I enter through the setter and the getter functions. Is there a way to do that ?