object oriented- inheritance

I wrote a code to calculate tax of some vehicles with different properties.But it gives lots of errors. Please help me urgent :)

my cpp file seems:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// try 4.cpp : main project file.
#include "stdafx.h"
#include <fstream>
#include <string>
#include <algorithm>
#include "try4class.h"
using namespace std;
int main()
{	ifstream myFile ("vehicle_list.txt");
	ofstream yourfile;
	yourfile.open("vehicle_tax.txt");
float tax;
	struct owner{
			string name;
			string surname;
			string ID;
		};
	struct vehicle{
		string brand;
		char group;
		struct owner owner_id;
		int type,model, engine_size, plate_number,number_seat, permission,tonnage ;
	};
		Poly *poly;
		commer commveh;
		longv longveh;
		privatev privateveh;
	for(int i=0;i<12;i++){
		struct vehicle vehhi;
		ifstream myFile ("vehicle_list.txt");
		myFile >> vehhi.type;
		myFile >> vehhi.brand;
		myFile >> vehhi.model;
		myFile >> vehhi.engine_size;
		myFile >> vehhi.owner;
		myFile >> vehhi. plate_number;
		if(vehhi.type==1){
			poly= &commveh;
			myFile >> vehhi.number_seat;
			myFile >> vehhi.permission;
			commveh.setVarscomm(vehhi.seat,vehhi.engine,vehhi.permission);
			cout << commveh.calculate_tax_commercial(seat,engine,perm);
		}
		if(vehhi.type==2){
			poly= &longveh;
			myFile >> vehhi.tonnage;
			myFile >> vehhi.permission;
			poly.setVarslong(vehhi.tonnage,vehhi.engine,vehhi.permission);
		}
		if(vehhi.type==3){
			poly= &privateveh;
			myFile >> vehhi.group;
			poly.setVarsprivate(vehhi.engine,vehhi.group);
		}}
return 0;
}


my header file seems:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "stdafx.h"
#include <iostream> 
#include <math.h>
using namespace std;
class Poly{
protected:
	float tax;
	char group;
	int seat,ton, perm ;
	float engine;
public: 
	Poly();
	virtual void setVarscomm(int num, float eng, int allow){
		seat=num;
		engine=eng;
		perm=allow;}	
	virtual	void setVarslong(int num, float eng, int allow){
		ton=num;
		engine=eng;
		perm=allow;}
	virtual void setVarsprivate(float eng,char ch){
		engine=eng;
		group=ch;}};
	
	class commer: public Poly{
		public:
			commer()
	{			Poly();}
			void setVarscomm(int num, float eng, int allow){
				seat=num;
				engine=eng;
				perm=allow;
	}	
	float calculate_tax_commercial(int seat, float engine, int perm){
			tax=60*seat +0.8*engine;
			if(perm==0)
				return tax;
			if(perm==1)
				return tax=(tax*150)/100;}};
	class longv: public Poly{
		public:
			longv(){
				Poly();}
			void setVarslong(int num, float eng, int allow){
				ton=num;
				engine=eng;
				perm=allow;}
			float calculate_tax_long(float ton, float engine, int perm){
			tax=100*ton +0.6*engine;
			if(perm==0){
				return tax;	}
			if(perm==1){
				tax=(tax*170)/100;
				return tax;	}}};
		class privatev: public Poly{
		public: 
			privatev(){
				Poly ();}
			void setVarsprivate(float eng,char ch){
				engine=eng;
				group=ch;}
			float calculate_tax_private(float engine, char group){
				if(group=='A')
					return tax=0.7*engine;
				if(group=='B')
					return tax=0.6*engine;
				if(group=='C')
					return tax=0.5*engine;}
};
Hi there,

Could you please post the errors along with the code?
That makes it a lot easier for us to see what's going wrong.

Thanks!

All the best,
NwN
thank you!

1> try 4.cpp
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(5): error C2011: 'Poly' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(5) : see declaration of 'Poly'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(25): error C2011: 'commer' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(25) : see declaration of 'commer'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(40): error C2011: 'longv' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(40) : see declaration of 'longv'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(55): error C2011: 'privatev' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(55) : see declaration of 'privatev'
1>try 4.cpp(25): error C2079: 'commveh' uses undefined class 'commer'
1>try 4.cpp(26): error C2079: 'longveh' uses undefined class 'longv'
1>try 4.cpp(27): error C2079: 'privateveh' uses undefined class 'privatev'
1>try 4.cpp(40): error C2440: '=' : cannot convert from 'int *' to 'Poly *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>try 4.cpp(43): error C2039: 'setVarscomm' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>try 4.cpp(44): error C2039: 'calculate_tax_commercial' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>try 4.cpp(47): error C2440: '=' : cannot convert from 'int *' to 'Poly *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>try 4.cpp(50): error C2039: 'setVarslong' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>try 4.cpp(53): error C2440: '=' : cannot convert from 'int *' to 'Poly *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>try 4.cpp(55): error C2039: 'setVarsprivate' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hi there,

1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(5): error C2011: 'Poly' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(5) : see declaration of 'Poly'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(25): error C2011: 'commer' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(25) : see declaration of 'commer'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(40): error C2011: 'longv' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(40) : see declaration of 'longv'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(55): error C2011: 'privatev' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(55) : see declaration of 'privatev'


I believe these are called because you don't have any include guards in your header file:

1
2
3
4
#ifndef POLYH
#define POLYH
//your current code in here
#endif 


That prevents the file from being included more than once, and thus the classes being "redefined".

Try that, it could possibly solve the larger part of the other errors.

Hope that helps.

All the best,
NwN
thank you so much but it says: unable to start program, system coul not find the file. build errors:

>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(8): error C2011: 'Poly' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(8) : see declaration of 'Poly'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(28): error C2011: 'commer' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(28) : see declaration of 'commer'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(43): error C2011: 'longv' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(43) : see declaration of 'longv'
1>c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(58): error C2011: 'privatev' : 'class' type redefinition
1> c:\users\hp\documents\visual studio 2010\projects\try 4\try 4\try4class.h(58) : see declaration of 'privatev'
1>try 4.cpp(25): error C2079: 'commveh' uses undefined class 'commer'
1>try 4.cpp(26): error C2079: 'longveh' uses undefined class 'longv'
1>try 4.cpp(27): error C2079: 'privateveh' uses undefined class 'privatev'
1>try 4.cpp(40): error C2440: '=' : cannot convert from 'int *' to 'Poly *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>try 4.cpp(43): error C2039: 'setVarscomm' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>try 4.cpp(47): error C2440: '=' : cannot convert from 'int *' to 'Poly *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>try 4.cpp(50): error C2039: 'setVarslong' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>try 4.cpp(53): error C2440: '=' : cannot convert from 'int *' to 'Poly *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>try 4.cpp(55): error C2039: 'setVarsprivate' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Did you make the changes suggested it the previous post? If so please re-post the contents of your include file.
Hi,

Are you sure that #include "try4class.h" :

1) is called try4class.h?
2) is in the same directory as the .cpp file?

All the best,
NwN
yes i am sure :)
jlb wrote:
Did you make the changes suggested it the previous post? If so please re-post the contents of your include file.


-N
i did some corrections but the only error is the system cannot find the file.

error:

1>c:\users\hp\documents\visual studio 2010\projects\try5\try5\stdafx.h(10): fatal error C1083: Cannot open include file: 'try4class.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Did you add try4class.h to the stdafx.h header? If so I would remove it from there. Just keep the include in your .cpp file
no it is not included to stdafx. only in cpp.

but i tried both :)
This sounds like an issue with the pre-compiled headers because the compiler is complaining about stdafx.h not being able to find your include file. You may want to try turning off this feature and commenting out stdafx.h and see if that helps.
Topic archived. No new replies allowed.