I must make a class of tyres.

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
Can you create a struct with the same information?
If so, classes are nearly the same thing.
If not, you need to do some studying:
http://www.cplusplus.com/doc/tutorial/structures/
http://www.cplusplus.com/doc/tutorial/classes/

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;
}

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
Topic archived. No new replies allowed.