Jump to content

Classes?


CoolMaster

Recommended Posts

int vinylRecord::compareRecords(vinylRecord temp1,vinylRecord temp2,int num)

int compareRecords(vinylRecord temp2,int num);

 

^^ and the prototypes

Do you see how the prototype is different from the declaration? That makes the compiler confused :)

Share this post


Link to post
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

but how would I compare then when in the actual function im like if temp1>temp2.......what would I do?

 

cause i made it like

int vinylRecord::compareRecords(vinylRecord temp1,vinylRecord temp2,int num)

 

but now it's complaining about this function does not take 2 parameters when I call it like this

 

cout<<"\nCompare by purchase date: "<<temp1.compareRecords(temp2, 1);

Edited by CoolMaster

Share this post


Link to post
Share on other sites

hmmm this gave me no errors,

i called it like this

 

cout<<"\nCompare by purchase date: "<<temp1.compareRecords(temp2, 1);

 

here's the function

int vinylRecord::compareRecords(vinylRecord temp2,int num)

{


 if(num==1)
{
	if(puryear<temp2.puryear)
	{
	return -1;
	}

	if(puryear>temp2.puryear)
	{
	return 1;
	}

	if (puryear==temp2.puryear && purmonth<temp2.purmonth)
	{
	return -1;
	}

	if (puryear==temp2.puryear && purmonth>temp2.purmonth)
	{
	return 1;
	}

	if (puryear==temp2.puryear && purmonth==temp2.purmonth && purday < temp2.purday)
	{
	return -1;
	}

	if (puryear==temp2.puryear && purmonth==temp2.purmonth && purday > temp2.purday)
	{
	return 1;
	}

	if(puryear==temp2.price && purmonth==temp2.purmonth && purday==temp2.purday)
	{
	return 0;
	}


}


if(num==2)
{
	if(price>temp2.price)
	{
		return -1;
	}
	if(price==temp2.price)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

 if(num==4)
{
	if(saleprice>temp2.saleprice)
	{
		return 1;
	}
	if(saleprice==temp2.saleprice)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}





  if(num==3)
{
	if(rating>temp2.rating)
	{
		return 1;
	}
	if(rating==temp2.rating)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}


cout << '\n' << '\n';

}

 

and header file proto

int compareRecords(vinylRecord temp2,int num);

 

basically i took the temp1. salesprice and just made it salesprice, since i called it as temp1.comparerecords

and since im just comparing 1 to 2....then it should work...i hope

i dunno if thats the right way or not tho lol

 

 

EDIT: WOOT IT COMPARES CORRECTLY HECK YES!!!!!!!!!!

i think i actually understand classes now, when u call a function u can store it directly into something, and then store what u stored to a temp variable

 

like temp1.readrecord

 

and it keeps those values, until u store it or change the actual things (price,name,album) etc...

Edited by CoolMaster

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...