Simple C++ Car Class

Simple C++ Car Class Homework Sample

You need to write a class to represent models of Ferrari cars. Each instance has a model name (a string), and a year (an integer). You need getters and setters for the name and year, and a method sameCar which compares 2 instances to see if they are the same (same year and model). We can also handle far more complicated C++ programming assignments than this, so contact us for a quote.

Solution:

ferrari.h

#ifndef FERRARI_H
#define FERRARI_H
#include”ferrari.cpp”
#endif // !FERRARI_H

ferrari.cpp

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

class Ferrari
{
public:
Ferrari()
{
}
Ferrari(const string model , const int year)
{
this->model = model;
this->year = year;
}

~Ferrari()
{
}
void setmodel(const string model)
{
this->model = model;
}
string getmodel()
{
return this->model;
}
void setYear(const int year)
{
this->year = year;
}
int getYear()
{
return this->year;
}
bool sameCar( Ferrari a)
{
return (a.getmodel() == (this->model) && a.getYear() == (this->year) );
}
void print()
{
cout << this->model << “(” << year << “)\n”;
}
private:
string model;
int year;

};

main.cpp

#include<iostream>
#include<string>
#include<algorithm>
#include”ferrari.h”
using namespace std;

int main()
{
Ferrari n;
n.setmodel(“YAMATA”);
n.setYear(1993);
n.print();
Ferrari m (“YAMATA”, 1993);

if (n.sameCar(m))
{
cout << “Same car\n”;
}
else {
cout << “NOt the same car\n”;
}
Ferrari z(“Ferrari”, 2018);
z.print();

if (n.sameCar(z))
{
cout << “Same car\n”;
}
else {
cout << “NOt the same car\n”;
}
system(“pause”);
return 0;
}