Please correct my mistake in following code que written above code

Que BMW car manufacturing company which produces the hatchback car on order basis for its customer
depending upon the life style and liking of the customer.
Create a class CAR having minimum attributes like no of attributes
1. no_of_wheels
2. name_of _company
3. color_of_car
4. no_of_seats
5. color_of_interior_upholstery
6. type_of_transmission
7. power steering (Boolean value :- YES/NO)
do the following:
1. identify the class and instance variables
2. Use the parameterized constructor to initialize the value of instance variables.
3. Create minimum three objects in another class having main method and display the values of
variables.

My Code




#include<iostream.h>
#include<conio.h>
void car()
{
clrscr();
class car
{
private:

int w=4;
char com[]="BMW";
char color[];
char trans[];
char inter[];
int seat=5;
bool s;


public:
void power(bool x)
{
s = x;
if(s==true)
{
cout<<"car has a power steering";
}
else
{
cout<<"car does not have power steering");
}
{
car(char[] x)
{
color=x;
}

}
}
class Company
{
void main()
{
car c1 ("black");
car c2 ("petrol");
car c3 ("ivory");
cout<<"colour of car:"<<c1.color;
cout<<"transmission mode of car:"<<c2.color;
cout<<"colour of interior upholstry of car:"<<c3.color;
c1.power(true);
}
}
}
it is giving following errors

Compiling CAR.CPP:
Error CAR.CPP 10: Cannot initialize a class member here
Error CAR.CPP 11: Cannot initialize a class member here
Error CAR.CPP 15: Cannot initialize a class member here
Error CAR.CPP 16: Type name expected
Error CAR.CPP 16: Declaration missing ;
Error CAR.CPP 20: 'bool' cannot start a parameter declaration
Error CAR.CPP 43: Improper use of typedef 'car'
Error CAR.CPP 43: Statement missing ;
Error CAR.CPP 44: Improper use of typedef 'car'
Error CAR.CPP 44: Statement missing ;
Error CAR.CPP 45: Improper use of typedef 'car'
Error CAR.CPP 45: Statement missing ;
Error CAR.CPP 46: Undefined symbol 'c1'
Error CAR.CPP 47: Undefined symbol 'c2'
Error CAR.CPP 48: Undefined symbol 'c3'
Error CAR.CPP 49: Undefined symbol 'true'
Error CAR.CPP 52: Declaration terminated incorrectly
Error CAR.CPP 22: Undefined symbol 's'
Error CAR.CPP 23: Undefined symbol 'true'
Error CAR.CPP 29: Statement missing ;
Error CAR.CPP 32: Expression syntax
Error CAR.CPP 37: ) expected
Error CAR.CPP 37: Statement missing ;
Error CAR.CPP 53: Declaration terminated incorrectly
Error CAR.CPP 53: Declaration missing ;
Error CAR.CPP 53: Too many error or warning messages
1
2
3
int w=4;
char com[]="BMW";
int seat=5;

You've got this in your class definition. This is wrong. Your class definition is a description of a new kind of object. You do not set values in a class definition. It makes no sense. Exactly where would that value 4 be stored? You've not created any objects yet; in a class definition, you're just explaining to the compiler what this new object looks like - you're not actually creating one.

car c1 ("black");
THAT is where you create an object, and now that the object exists, NOW you can set some values in it.


Also, this
void main() is NOT C++. It is NOT. If your compiler doesn't even warn you, throw it away and get a C++ compiler. If your textbook uses void main(), it's a bad book. If your teacher uses it, you're being taught some hideous language that looks a lot like C++ but isn't.

This
1
2
#include<iostream.h>
#include<conio.h> 

indicates that you're using a very old compiler. A compiler that predates the C++ standard. A compiler that's probably a decade old or more. Throw it away and get a C++ compiler.
Last edited on
i am a very novice programmer pls try compiling this code in your pc and correct the possible errors and post the xorrected codes please its very urgent my 50 nos depends on this it would be very kind of you
Topic archived. No new replies allowed.