I need help setting up a default constructor. This is in C++, my program compile
ID: 3767431 • Letter: I
Question
I need help setting up a default constructor. This is in C++, my program compiles but it doesnt print the correct outpt
#include "vehicle.h"
vehicle::vehicle()
{
//Displays an example; data already stored in the file
vin = "VHR12G3J589R";
make = "Nissan";
model= "Xterra";
year=2016;
price=32800;
}
vehicle::vehicle( string iVin, string iMake, string iModel, int iYear, double iPrice)
{
vin = iVin;
make = iMake;
model = iModel;
year = iYear;
price = iPrice;
} this is what it prints
how do i fix it so that it doesnt repeat the inventory?
thanks
Explanation / Answer
#include "functions.h"
using namespace std;
int main()
{
int var;
vector<string> vehicle;
{
string vin;
string make;
string model;
int year;
double price;
};
var = '1'; //These are the usuable variables
var = '2';
var = '3';
var = '4';
var = '5';
var = '6';
var = '7';
var = '8';
do // do loop execution
{
cout << "Please select an operation: ";
cout << "1: Display Inventory ";
cout << "2: Add a vehicle ";
cout << "3: Update a vehicle ";
cout << "4: Delete a vehicle ";
cout << "5: Sort inventory by VIN ";
cout << "6: Search inventory from file ";
cout << "7: Read inventory from file ";
cout << "8: Write inventory to file and exit ";
cin >> var;
switch (var)
{
case 1:
{
void displayInventory();
}
break;
case 2:
{
void addToInventory();
}
break;
case 3:
{
void updateInventory();
}
break;
case 4:
{
void deleteInventory();
}
break;
case 5:
{
void sortVehicle();
}
break;
case 6:
{
void searchInventory();
}
break;
case 7:
{
string vin;
string make;
string model;
int year;
double price;
getline(infile, vin);
getline(infile, make);
getline(infile, model);
getline(infile, year);
getline(infile, price);
}
break;
case 8:
{
void searchInventory();
}
break;
default:
{
cout << "Please enter a number ";
}
break;
};
} while (var != 8);
system("pause");
return 0;
}
#ifndef FUCNTION_H
#define FUCNTION_H
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
#include "vehicle.cpp"
#include "vehicle.h"
#include <vector>
using namespace std;
vector<string> vehicle;
{
string vin;
string make;
string model;
int year;
double price;
};
int i;
void displayInventory()
{
int i;
double MAX_SIZE = 100;
if (i > !MAX_SIZE)
{
cout << "Error: There is no more room to add entries. You will now be returned to the main menu." << endl;
}
else (i = 0, i < MAX_SIZE, i++);
{
cout << vehicle[i].getvin();
cout << vehicle[i].getmake();
cout << vehicle[i].getmodel();
cout << vehicle[i].getyear();
cout << vehicle[i].getprice();
}
};
void addToInventory()
{
int input;
int i;
double MAX_SIZE = 100;
do (i = 0, i < MAX_SIZE, i++)
{
cout << "Here you can add a vehicle to the database. " << endl;
cout << "Please enter the VIN number. " endl;
cin >> vehicle[i].setvin(); << endl;
cout << "Please enter the vehicle make ";
cin >> vehicle[i].setmake(); << endl;
cout << "Please enter the vehicle model ";
cin >> vehicle[i].setmodel(); << endl;
cout << "Please enter the vehicle year ";
cin >> vehicle[i].setyear(); << endl;
cout << "Please enter the vehicle price ";
cin >> vehicle[i].setprice(); << endl;
vehicle.push_back;
cout << "Enter a Y if you would like to input more data ";
cin >> input;
}
while (toupper(input) == 'Y');
if (i >! MAX_SIZE)
{
cout << "Error: There is no more room to add entries. You will now be returned to the main menu." << endl;
}
};
void updateInventory()
{
int i;
cout << "You are about to update an entry. ";
cout << "Choose a vehicle number from the inventory: ";
void displayInventory();
cin >> i;
i = i - 1;
cout << "What would you like to update? ";
cout << "1: Vehicle VIN ";
cout << "2: Vehicle Make ";
cout << "3: Vehicle Model ";
cout << "4: Vehicle Year ";
cout << "5: Vehicle Price ";
switch (var)
{
case 1:
{
cout << "Please enter the updated VIN: " << endl;
cin >> vehicle[i].setvin();
return 0;
}
break;
case 2:
{
cout << "Please enter the updated make: " << endl;
cin >> vehicle[i].setmake();
return 0;
}
break;
case 3:
{
cout << "Please enter the updated model: " << endl;
cin >> vehicle[i].setmodel();
return 0;
}
break;
case 4:
{
cout << "Please enter the updated year: " << endl;
cin >> vehicle[i].setyear();
return 0;
}
break;
case 5:
{
cout << "Please enter the updated price: " << endl;
cin >> vehicle[i].setprice();
return 0;
}
break;
default:
{
cout << "Please enter a number between 1 and 5. ";
}
break;
};
};
void deleteInventory()
{
cout << "You are about to delete an entry. ";
cout << "Choose a vehicle number from the inventory: ";
void displayInventory();
cin >> i;
i = i - 1;
vehicle.erase[i];
};
void sortVehicle() //(vector<vehicle> & myVector)
{
vehicle temp;
int number = myVector.size();
for (int i = 0; i < number; i++)
{
if (myVector[i + 1].getvin() < myVector[i].getvin())
{
temp = myVector[i];
myVector[i] = myVector[i + 1];
myVector[i + 1] = temp;
}
}
};
void searchInventory()
{
vector<string> vehicle;
{
string vin;
string make;
string model;
int year;
double price;
};
int size = vehicle.size();
string searchModel;
cout << "Please type the model you'd like to search for: " << endl << endl;
cin >> searchModel;
for (int i = 0, i > size, i++)
{
vehicle[i].getmake();
}
if (vehicle[i].getmake() = vehicle.make)
{
cout << vehicle[i];
}
};
#include "vehicle.h"
vehicle::vehicle()
{
vin = "VHR12G3J589R";
make = "Nissan";
model = "Xterra";
year=2016;
price=32800;
}
vehicle::vehicle(string ivin, string imake, string imodel, int iyear, double iprice)
{
vin = ivin;
make = imake;
model = imodel;
year = iyear;
price = iprice;
}
string vehicle::getvin() const
{
return vin;
}
string vehicle::getmake() const
{
return make;
}
string vehicle::getmodel() const
{
return model;
}
int vehicle::getyear() const
{
return year;
}
double vehicle::getprice() const
{
return price;
}
#include <iostream>
#include <string>
using namespace std;
#ifndef vehicle_HEADER
#define vehicle_HEADER
class vehicle
{
private:
string vin;
string make;
string model;
int year;
double price;
public:
vehicle();
vehicle(string, string, string, int, double);
string getvin() const;
string getmake() const;
string getmodel() const;
int getyear() const;
double getprice() const;
void setvin(string);
void setmake(string);
void setmodel(string);
void setyear(int);
void setprice(double);
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.