Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey friends, look my code I have 3 errors, how can I solve this? Please help me.

C++
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
class converter
	{
	char co;
public:
	conver(char co1)
		{
		co=co1;
		int s,s1,s2;
		char *p;
		p=strtok(co,".");
		if(p)
			{
			s=atoi(p)*12;
		}
		p=strtok(NULL,".");
		if(p)
			{
			s1=atoi(p);
		}
		s2=s+s1;
		return s2;
	}
};
class rectangle
	{
	char i,j,sqft,mul;
public:
	rec(char p,char q)
	{i=p;j=q;}
	char show_area();
};

char rectangle::show_area()
	{
	float a;
	float mul=0;
	converter ob1;
	a=ob1.conver(i)*ob1.conver(j);
	mul=a/144;
	return mul;
}
class triangle
	{
	char i1,j1;
public:
	tri(char p1,char q1)
		{
		i1=p1;
		j1=q1;
	}
	char show_area1();
};
char triangle::show_area1()
	{
	float a1,mul1=0;
	converter ob2;
	a1=ob2.conver(i1)*ob2.conver(j1)*(0.5);
	mul1=a1/144;
	return mul1;

}
class area:public rectangle,public triangle
	{
	char length,width,height;
public:
	area(char length1,char width1,char height1):rec(length1,width1),tri(length1,width1)
		{
length=length1;
width=width1;
height=height1

	}

void show()
	{
	mout<<"rectangl's area is:"<<show_area();
	mout<<"triangle's area is:"<<show_area1();
}



};
class volume :public area
	{
	char h,l,w;
public:
	volume(char lenght,char width,char height)
		{
		l=legth;
		w=width;
		h=height;
	}
	


void show_area2()
	{
	float a3,mul3=0;
	converter ob3;
	a3=ob3.conevr(l)*ob3.conver(w)*ob3.conver(h);
	mul3=a3/144;
	mout<<"Volume is:"<<a3;
}


};
int main()
	{
	char a[10],b[10],c[10];
	ifstream mit("inp.txt");
	ofstream mot("oup.txt");
	mit>>a>>b>>c;
	area ob(a,b,c);
	ob.show();
	volume obv(a,b,c);
	return 0;
}


But then it shows 3 errors:

1.C:\TC\BIN\mitu\assignment11.cpp(15) : error C2664: 'strtok' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

2.:\TC\BIN\mitu\assignment11.cpp(118) : error C2664: '__thiscall area::area(char,char,char)' : cannot convert parameter 1 from 'char [10]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

3.:\TC\BIN\mitu\assignment11.cpp(120) : error C2664: '__thiscall volume::volume(char,char,char)' : cannot convert parameter 1 from 'char [10]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
help me friends i really need help.
Posted
Updated 22-Aug-11 22:49pm
v3
Comments
Richard MacCutchan 23-Aug-11 7:21am    
There is so much wrong with this that it's difficult to know where to start. You need to go back to your C++ manual and study the basic concepts of the language, with particular reference to types, classes and functions.
Halima akhter 23-Aug-11 10:46am    
yes,sir i have just solve this problem
Richard MacCutchan 23-Aug-11 11:48am    
I think you will have a lot more to do yet.
Philippe Mori 23-Aug-11 8:09am    
The 3 errors messages are very clear... And by the way, it is also easy to get help on errors message either from Visual Studio or with Google. And you might even have some code samples that explain the error.

You need to think about what you are trying to do: strtok[^] takes a char* parameter not a char, just as the error explains.

C++
char co;
...
p=strtok(co,".");
So rather than trying to hand a single character at a time, why not pass it a string of them?
 
Share this answer
 
Comments
Halima akhter 23-Aug-11 4:55am    
now my code shows only one error .i changed co to *co.
char *co;
public:
conver(char co1)
{
co=co1;
int s,s1,s2;
char *p;
p=strtok(co,".");

but it shows one error with the the line "co=co1"
Prerak Patel 23-Aug-11 5:01am    
because, co1 is char, which again cannot be converted to char*
OriginalGriff 23-Aug-11 5:06am    
Yes, and it is still rubbish!
strtok works on a sequence of characters, not a single character. co1 is a sinmgle character, so even if you pointed co at it with
co=&co1;
strtok would still not have enough to work on!
Think about what you are trying to do, because I don't believe that that code is ever going to do it, whatever it is! :laugh:
Stefan_Lang 23-Aug-11 8:01am    
'why not pass it a string of them?'

Because he doesn't have one.

And besides he doesn't need one either, nor the entire converter class - see my solution.
OriginalGriff 23-Aug-11 8:22am    
That's why I've been saying "think about what you are trying to do" - because I don't think he quite knows what he is tryign to do...:laugh:
1. In p=strtok(co,".");, co is char and not char*.
It is supposed to be used with two char* parameters.
C++
char * strtok ( char * str, const char * delimiters );


For 2 and 3, you are passing char[] where char is required as parameter.
 
Share this answer
 
Comments
Halima akhter 23-Aug-11 4:35am    
i changed char co to char *co . but it still shows error .
Prerak Patel 23-Aug-11 5:01am    
Yes, co1 is char, which again cannot be converted to char*.
1. Even TC comes with help files that indicate the use of various functions.

2. char* does not equal char

3. You should use variable with _meaningful names_, had this be done it may be possible to guess what you hoped to achieve with the converter class.

4. The return type of converter::conver is not defined.

5. You pass a single byte to the conver member-function, yet treat it as though it was a string.


It would be a prudent move if you would state what you are trying to achieve.
From what I can tell, you should delete all references to the class "converter".
You appear to be passing binary values to "conver" before pretending that they are strings and proceeding to convert these strings to a numerical representation. wtf?

Take for example this snippet:
void show_area2()
	{
	float a3,mul3=0;
	converter ob3;
	a3=ob3.conevr(l)*ob3.conver(w)*ob3.conver(h);
	mul3=a3/144;
	mout<<"Volume is:"<<a3;
}


Disregarding the conversion factor of 144(which bears no impact on the result), this would be quite simply rewritten as:
void show_area2()
{
	mout<<"Volume is:"<< (l *  w * h);
}
 
Share this answer
 
So you're new to coding.
I'm not going to answer the question you asked, but I will give you some advice on coding style.

I'm not sure where you came up with the bracket alignment scheme you are using but it's not one I've seen in my 12+ years of coding C++ unless it goes way back to K&R.

You will not be the only person to ever read the code you write, this being one example. If you work in software development then work colleagues will also need to read your code.
Using a common coding style makes it easier for other people to read and understand your code.

Your current coding style makes it difficult for me to see at a glance what starts where, so the first thing I need to do when looking at your code is figure out where the classes are, and where the function implementations start before I go looking at what the code does. I'm wasting time I could spend solving your problem on deciphering the structure of your code. (actually I don't waste time on this, I just didn't even attempt to look at the code causing you problems)

I would suggest you find a more recent C++ coding style and start using it.

Good luck, and have fun coding.
 
Share this answer
 
v2
Forget the compiler errors. They are the least of your problems - in fact, since you don't even have values that you can meaningfully apply the function strtok() on, it is the wrong function anyway, no matter what your intention was!

Apparently you do not know what a class is for either, much less how to use inheritance. I suggest that you completely forget classes for now and start learning some basics of C before you delve into OOP. Before you object, consider this: the basic meaning of
C++
class B : public C

is that 'B' is a 'C'. or in other words, 'C' is a more general form of 'B', or 'B' is a special case of 'C'. With that in mind, look at this line from your code and tell me what it means:
C++
class area:public rectangle,public triangle


From your code I can see that you wish to calculate and print areas of a rectangle and triangle, given a few measures that you provide from an input text file. Obviously you also intend to calculate some volume, but there is no code existant for that and no indication as to what shape of object you want to calculate the volume of.

Starting at the input, you are using ifstream to read some values. That is fine, but you seem to be missing the power of this class: instead of reading these values into char arrays, you could just as well directly read the float (or double or int) values that you actually want! That way you don't need to take care of the string-to-value conversion at all! In other word you don't need that converter class, ifstream already does it for you:

C++
int main() {
   float a, b, c;
   ifstream mit("inp.txt");
   mit >> a >> b >> c;


Then you define your shapes: triangles and rectangles so far, using these values. Since these values don't fully define general objects of the type rectangle or triangle however, the question is whether your point really is to define these shapes, or rather their geometrical properties. Apparently all you want is their area (for now at least), so just define two functions:

C++
float triangle_area(float width, float height) {
   return width * height / 2.0;
}
float rectangle_area(float width, float height) {
   return width * height;
}


That is about all you need, as far as the current functionality of your code is concerned.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900