Feb 29, 2016 at 2:24pm Feb 29, 2016 at 2:24pm UTC
Well as a beginner i have to make a class of Tires(exam) with the following properties:
1) Width (inches),
2) Radius (inches),
3) Rim (inches),
4) Type - 0: all weather
1: dry
2: rain
4: snow,
5) Brand,
6) Model,
7) Year
I don't have the experience to make that and i need help to understand how it works.
Last edited on Feb 29, 2016 at 2:29pm Feb 29, 2016 at 2:29pm UTC
Feb 29, 2016 at 4:17pm Feb 29, 2016 at 4:17pm UTC
Thank you, i think this is correct:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
class Tires
{
private:
double width;
double radius;
double rim;
int type;
char brand[40];
char model[40];
int year;
public:
Tires();
Tires(double w,double r,double rim,int t,const char b[40] , const char m[40] , int y);
};
Tires::Tires(double w,double r,double rim,int t,const char b[40] , const char m[40] , int y)
{
cout << (this->width=w) << endl;
cout << (this->radius=r) << endl;
cout << (this->rim=rim) << endl;
cout << (this->type=t) << endl;
strcpy(this->brand,b) ;
cout << brand << endl;
strcpy(this->model,m) ;
cout << model << endl;
cout << (this->year=y) << endl;
}
int main()
{
Tires c(2.5, 2.3, 3.4, 3, "BMW", "i8", 2015);
return 0;
}
Feb 29, 2016 at 4:53pm Feb 29, 2016 at 4:53pm UTC
Your default constructor is not defined.
You should separate output functionality from initialization functionality in your parameterized constructor. i.e. Create a print() function that will display the attributes of a tire.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on Feb 29, 2016 at 6:10pm Feb 29, 2016 at 6:10pm UTC