Classes

Hey guys, i'm having the biggest problem completing my worksheet. Its about classes.. Please help me...
explian please?
Create a class called EmpCar.
i) Its private data members should include: char model [10], int year, and const int seral no.
ii) The class should use composition to include an object of Employee class into the class in order to get the employees name
iii) The class should have a constructor that initializes all its private data members.
iv) Class EmpCar should have have a friend function called carlover() that will be able to modify the year of the car.
i just posted the question
do you have source code and error messages?
no i don't, i got that question and i don't know the first thing to do :-(
well have you used classes before?
no, never
Last edited on
http://cplusplus.com/doc/tutorial/classes/

make both of your classes and then i will help with the "friend" of the class part
Last edited on
How do u do the composition part of it?
the best explaination is here:

http://cplusplus.com/forum/beginner/12899/
ok...
1
2
3
4
5
class Computer
{
private:
  Motherboard mobo;
};


from what i understand you are making a class variable inside a class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Employee
{
  ..........
  ............ 
 ...........
};

// new class

class EmpCar
{
private:
             char model [10];
             int year;
             int seral no;
             Employee emp ; 

public:
         EmpCar();        
       ..............
       ...............


};
EmpCar::EmpCar()
{
    year = 0 ; 
    serialno = 0;
}
Thanx guys (y)
Topic archived. No new replies allowed.