3 Replies - 466 Views - Last Post: 07 June 2009 - 05:54 PM Rate Topic: -----

#1 Ranma344  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-May 09

[C++] Having a few errors.

Posted 07 June 2009 - 02:39 PM

Hello, I am getting a few errors with the code shown below, and I have not been able to figure them out. I would appreciate any help that anyone could give me.

#include <iostream>
#include <string>
using namespace std;

class drinks {
			  int amount; //in oz
			  double price;
			  string name;
			  bool hot;
			  bool carbonated;
			  string color;
	  public:
			 drinks(string n, bool h, bool c, string co, double p, int a) {
						   name = n;
						   hot = h;
						   carbonated = c;
						   color = co;
						   price = p;
						   amount = a;
			 }
			 
			 void set_Name(string n) {
				  name = n;
			 }
			 void set_Hot(bool h) {
				  hot = h;
			 }
			 void set_Carbonated(bool c) {
				  carbonated = c;
			 }
			 void set_Color(string co) {
				  color = co;
			 }
			 void set_amount(int a) {
				 amount = a;
				 }
			 void set_price(double p) {
				 price = p;
			 }
			 string get_Name() {
					return name;
			 }
			 bool get_Hot() {
				  return hot;	 
			 }		 
			 bool get_Carbonated() {
				  return carbonated;
			 }
			 string get_Color() {
					return color;
			 }
			 int get_amount() {
				 return amount;
				 }
			 double get_price() {
					return price;
			 }
			 
			 drinks operator+ (const drinks& beverage) const {
					drinks tempDrink();
					tempDrink.set_amount(amount + beverage.get_amount());
					tempDrink.set_price(price + beverage.price);
					return tempDrink();
					}
			 bool operator== (const drinks& beverage) const {
					return (price == beverage.price && amount == beverage.amount);
					} 
			 void display_Information() {
				  cout << "The name of the drink is: " << name << endl;
				  if (hot) {
						   cout << "The drink is hot." << endl;
				  }else {
						cout << "The drink is cold." << endl;
				  }
				  if (carbonated) {
						   cout << "The drink is carbonated." << endl;
				  }else {
						cout << "The drink is not carbonated." << endl;
				  }
				  cout << "The color of the drink is: " << color << endl;
			 }
};
  
	  
int main() {
	drinks tea("Lipton", false, false, "brown", 1.29, 20);
	drinks soda("Pepsi", true, false, "brown", 1.25, 22);
	drinks Combo();
	Combo = tea+soda;
	
	if (tea==soda) cout << "Same!";  else cout << "Not Same!" << endl;
	cout << Combo.display_Information();


	  system("pause");
	  return 0;
}


The errors are as follows:
	 C:\Dev-Cpp\Untitled2.cpp In member function `drinks drinks::operator+(const drinks&) const': 
61 C:\Dev-Cpp\Untitled2.cpp request for member `set_amount' in `tempDrink', which is of non-class type `drinks ()()' 
61 C:\Dev-Cpp\Untitled2.cpp passing `const drinks' as `this' argument of `int drinks::get_amount()' discards qualifiers 
62 C:\Dev-Cpp\Untitled2.cpp request for member `set_price' in `tempDrink', which is of non-class type `drinks ()()' 
	 C:\Dev-Cpp\Untitled2.cpp In function `int main()': 
89 C:\Dev-Cpp\Untitled2.cpp assignment of function `drinks Combo()' 
89 C:\Dev-Cpp\Untitled2.cpp cannot convert `drinks' to `drinks ()()' in assignment 
92 C:\Dev-Cpp\Untitled2.cpp request for member `display_Information' in `Combo', which is of non-class type `drinks ()()' 


Is This A Good Question/Topic? 0
  • +

Replies To: [C++] Having a few errors.

#2 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: [C++] Having a few errors.

Posted 07 June 2009 - 02:44 PM

Try adding an empty constructor to your class:

drinks()
{


}


Was This Post Helpful? 0
  • +
  • -

#3 Ranma344  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-May 09

Re: [C++] Having a few errors.

Posted 07 June 2009 - 02:56 PM

Huh, I always seem to skip over the extremely simple things, that indeed fixed the problem. Thank you very much.
Was This Post Helpful? 0
  • +
  • -

#4 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 977
  • Joined: 09-May 09

Re: [C++] Having a few errors.

Posted 07 June 2009 - 05:54 PM

you seem to be doing a few things wrong here


1. add default constructor
2. you have already set your details in the constructor (no need to use set functions)
3. tempDrink.set_amount( expects 1 variable) // declared as "void set_amount(int a)"
4. drinks tempDrink(); // this is wrong use drinks tempDrink; // drinks is the class and tempDrink is an object
5. do u have a class called baverage?

Hope this helps
Kevin
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1