This is what I got so far!
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
//Car Class
class Car
{
protected:
string make; //make
string model; // model
string color; // color
int year; // year
int mileage; // miles on car
int IntStackSize;
int top; //top of stack
public:
//Constructor that will set information for a new car
void New_vehicle (string a, string b, string c, int d, int e)
{make = a; model = b; color = c; year = d; mileage = e;}
Car(); //Default constructor
Car(string, string, string, int, int);
//Stack Information
void push(int);
void pop(int &);
bool isFull();
bool isEmpty();
//mutator and accessor functions
void setMake(string);
void setModel(string);
void setColor(string);
void setYear(int);
void setMileage(int);
string getMake();
string getModel();
string getColor();
int getYear();
int getMileage();
//Check mileage to see if valid
void valid_mileage(int);
void car_details();
string string_car_details();
};
//Sets to default values
Car::Car() {
make = " ";
model = " ";
color = " ";
year = 0;
mileage = 0;
}
// My Vehicle set up(Make, model, color, year, mileage)
Car::Car(string make, string model, string color, int year, int mileage) {
this->make = make;
this->model = model;
this->color = color;
this->year = year;
valid_mileage(mileage);
}
void Car::setMake(string make) {
Car::make = make;
}
void Car::setModel(string model) {
Car::model = model;
}
void Car::setColor(string color) {
Car::color = color;
}
void Car::setYear(int year) {
Car::year = year;
}
void Car::setMileage(int mileage) {
valid_mileage(mileage);
}
string Car::getMake() {
return make;
}
string Car::getModel() {
return model;
}
string Car::getColor() {
return color;
}
int Car::getYear() {
return year;
}
int Car::getMileage() {
return mileage;
}
void Car::valid_mileage(int mileage) {
if (mileage>=0)
Car::mileage=mileage;
else {
Car::mileage=0;
cout << "WARNING! You have entered invalid mileage!\n";
}
}
void Car::car_details() {
cout << "The current car is a " << year << ' ' << color << ' '
<< make << ' ' << model << " with " << mileage << " miles.\n\n";
}
string Car::string_car_details() {
stringstream buf;
buf << "The current car is a " << year << ' ' << color << ' '
<< make << ' ' << model << " with " << mileage << " miles.\n\n";
return buf.str();
}
Code:
#include "CarClass.h"
using namespace std;
Car::Car(string make, string model, string color, int year, int mileage)
{
const int SIZE = 6;
Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 45000),
Car("Ford", "Mustang", "Red", 2007, 12600),
Car("Voltzwagon", "Jetta", "Black", 2006, 20218),
Car("Jeep", "Cherokee", "White", 2000, 98322),
Car("Nissan", "Sentra", "Red", 2002, 76046),
Car("Voltzwagon", "Beetle", "Black", 2005, 28031)};
top =-1;
}
//Set up Stack Push
void Car::push(int num)
{
if (isFull())
{
cout << "The Stack is Full!\n";
exit(1);
}
else
{
top++;
Car_array[top] = num;
}
}
//Set up Stack Pop
void Car::pop(int &num)
{
if (isEmpty())
{
cout << "The Stack is Empty!\n";
exit(1);
}
else
{
num = Car_array[top];
top--;
}
}
bool Car::isFull()
{
if (top == IntStackSize -1)
return true;
else
return false;
}
bool Car::isEmpty()
{
if (top == -1)
return true;
else
return false;
}
int main() {