need fast help(novice)

homework help(3 hours till class)

Page 1 of 1

10 Replies - 948 Views - Last Post: 09 November 2009 - 10:25 PM Rate Topic: -----

#1 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

need fast help(novice)

Posted 05 November 2009 - 08:48 AM

#include <cstdlib>
#include <iostream>

using namespace std;

class employee{
	  public: 
				 int id;
				 
	
	   employee(){;}

	
	
	   ~employee(){};
	   
	   
	 
   
};

class salaried: public employee
{	  private:
	  double wk_pay;
	  public:
	   salaried (int i, double weeklypay)
		{id=i;
		wk_pay=weeklypay; }


	friend ostream & operator<<(ostream& out, const salaried &empinfo)
	 {out<<"The employee's  id is "<< empinfo.id<<endl;
	  out<<"The employee's weekly pay is "<<empinfo.wk_pay<<endl;}

   
};


class hourly: public employee
{protected:
		double hrly_pay;
	 
public:
		hourly(int no_use, double hourlypay)
		{hrly_pay=hourlypay;
		id=no_use; }
   friend hourly & operator * ( const hourly)
	 { hourly temp(0,0);
	 temp.hrly_pay = hrly_pay * 40;
	temp.id=id;
	 return (temp);}


friend ostream & operator<<(ostream& out, const hourly &empinfo)
	 {out<<"The employee's  id is "<< empinfo.id<<endl;
	  out<<"The employee's weekly pay is "<<empinfo.hrly_pay<<endl;}
	 

 
  

  
};




int main(int)
{
	double answer;
	
	salaried smith(111,1500);
	hourly jones(222,10.75);
	cout<<smith;
	cout<<smith*jones;
	
	
	
	
	
	
	
	
	
	
	
	
	
	system("PAUSE");
	return EXIT_SUCCESS;
}

}




ok theres my code

im having trouble with overloading the multiplication operator. I simply want it to multiply the 10.75 of the second object( to get wkly pay) by 40. and return the result.

also having lot of trouble calling the * operator
cout<<smith works fine but how do incorperate the * into cout<<jones


thx for help
class soon pls help1!!

edit: i have it displaying the hrly pay for jones but i need it to display the wkly pay...which means i need to call the overloaded * function

how do i do that? right now its cout<<jones;

if i try to put the * in there i get errors

This post has been edited by sweetlipz: 05 November 2009 - 08:53 AM


Is This A Good Question/Topic? 0
  • +

Replies To: need fast help(novice)

#2 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

Re: need fast help(novice)

Posted 05 November 2009 - 08:55 AM

bumppppp
Was This Post Helpful? 0
  • +
  • -

#3 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

Re: need fast help(novice)

Posted 05 November 2009 - 09:07 AM

bump
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: need fast help(novice)

Posted 05 November 2009 - 09:14 AM

Don't bump this thread again, or I'll ban you.
Was This Post Helpful? 0
  • +
  • -

#5 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

Re: need fast help(novice)

Posted 05 November 2009 - 11:43 AM

i tried multiplying jones and smith but i get a different error this time, it doesnt makes sense
Was This Post Helpful? 0
  • +
  • -

#6 hackterr  Icon User is offline

  • D.I.C Regular

Reputation: 21
  • View blog
  • Posts: 293
  • Joined: 13-August 09

Re: need fast help(novice)

Posted 05 November 2009 - 11:51 AM

Is overloading absolutely necessary?
If not then get rid of it and do it using a function cos your code shows that u do not understand it fully yet

This post has been edited by hackterr: 05 November 2009 - 11:52 AM

Was This Post Helpful? 0
  • +
  • -

#7 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

Re: need fast help(novice)

Posted 05 November 2009 - 03:37 PM

my teacher said this program has to have the mult sign and the << overloaded for this assignment.


i dont understand it? overloading is pretty much same thing as a function

jus dont know how to call it properly

can any1 help? i had this topic opened for 6 hours and no1 can seem to help me!
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: need fast help(novice)

Posted 05 November 2009 - 04:53 PM

Maybe this link will help? Note...I found this by searching for "overloading multiplication operator c++" in Google. It was the first link there. Also, if you go to the next page on that tutorial, you know what's there? Overloading I/O Operators.

Google really is a pretty cool tool.
Was This Post Helpful? 0
  • +
  • -

#9 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

Re: need fast help(novice)

Posted 09 November 2009 - 07:21 PM

View PostJackOfAllTrades, on 5 Nov, 2009 - 03:53 PM, said:

Maybe this link will help? Note...I found this by searching for "overloading multiplication operator c++" in Google. It was the first link there. Also, if you go to the next page on that tutorial, you know what's there? Overloading I/O Operators.

Google really is a pretty cool tool.



i tried ur link and it was revalent but i still cant get it to work

if any1 can get the above code sorted out it would mean the world to me, i spent at least 7 hours on it and its driving me crazy

its beginner stuff so im suprised no1 rli said anything helpful

im reall trying to find out how to call my overloaded * operator properly along with my objeect
Was This Post Helpful? 0
  • +
  • -

#10 cdarklight  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 70
  • Joined: 15-August 09

Re: need fast help(novice)

Posted 09 November 2009 - 08:44 PM

Is it supposed to multiply the pay of both and return a total? or simply multiply by 40 when multiplying with a weekly?

This post has been edited by cdarklight: 09 November 2009 - 08:48 PM

Was This Post Helpful? 1
  • +
  • -

#11 sweetlipz  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 35
  • Joined: 01-December 08

Re: need fast help(novice)

Posted 09 November 2009 - 10:25 PM

View Postcdarklight, on 9 Nov, 2009 - 07:44 PM, said:

Is it supposed to multiply the pay of both and return a total? or simply multiply by 40 when multiplying with a weekly?


its supposed to multiply by 40 with a hourly to get the weekly

This post has been edited by sweetlipz: 09 November 2009 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1