Classes

I am creating a program, these are the requirements:

We are going to write a program to figure out if several elements are boiling or melting.

Substance---Melting Point---- Boiling Point
Zinc(Zn)--- (787.15°F)--------(1665°F)
Barium(Ba)- (1341°F)----------(3353°F)
Mercury(Hg)-(-37.89°F)------- (674.11°F)
Uranium(U)--(2070°F)----------( 7468°F)


Design a class that stores a temperature in a temperature member variable and has the appropriate accessor and mutator functions.

In addition to appropriate constructors, the class should have the following member functions for each of the elements:

• isZincMelting. This function should return the bool value true if the temperature stored in the temperature field is at or above the melting point and below the boiling point of zinc. Otherwise, the function should return false.

• isZincBoiling. This function should return the bool value true if the temperature stored in the temperature field is at or above the boiling point of zinc. Otherwise, the function should return false.

• Similarly you should have isBariumMelting, isBariumBoiling

• Similarly you should have isMercuryMelting, isMercuryBoiling

• Similarly you should have isUraniumMelting, isUraniumBoiling

Write a program that demonstrates the class.

The program should ask the user to enter a temperature, and then display a list of the substances that will melt at that temperature and those that will boil at that temperature.

For example, if the temperature is 1764 the class should report:

Zinc boils, Barium melts, Mercury boils and Uranium is solid

--This is what I have so far and I am getting some errors.
*In function 'int main()':
69:21: error: no matching function for call to 'Elements::isZincMelting()'
69:21: note: candidate is:
51:6: note: bool Elements::isZincMelting(float)
51:6: note: candidate expects 1 argument, 0 provided
In member function 'bool Elements::isZincMelting(float)':
56:1: warning: control reaches end of non-void function [-Wreturn-type]

Any help is appreciated. Thank you

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
  #include<iostream> 
#include <cmath>
#include <algorithm>
#include <cstdio>


using namespace std;

class Elements
{
	private:
		float temp;
	
	public:
		//float getTemp() const; //Get user temp
		void setTemp(float);
		bool isZincMelting(float);
		bool isZincBoiling(float);
		bool isBariumMelting(float);
		bool isBariumBoiling(float);
		bool isMercuryMelting(float);
		bool isMercuryBoiling(float);
		bool isUraniumMelting(float);
		bool isUraniumBoiling(float);
		
		
};
//setTemp
void Elements::setTemp(float temp)
{
	temp = t;
}

bool Elements::isZincMelting( float temp)
{
	if (t >= 787.15 && t < 1665)
		return true;
	
}

int main()
{
	Elements info; //Define an instance of Element class 
	float getTemp;
	
	cout << "Enter a temperature: " << endl;
	cin >> getTemp;
	
	//Store in temp of element info object
	info.setTemp(getTemp);
	
	info.isZincMelting();
	
	
	return 0;
}
Last edited on
line 31,36: where is t defined? Did you mean temp? Which temp? The argument or the member variable? Hint: Don't name your arguments the same as your member variables.

Line 38: What is returned if the condition is false?
Lines 34-39 can be simplified as follows:
1
2
3
bool Elements::isZincMelting ()
{  return (temp >= 787.15 && temp < 1665);
}


line 52: Your declaration (line 17) says isZincBoiling() requires a float. You're not passing a float. You also don't do anything with the result of calling the bool function.

You're mixing styles. You have and use a setter for the temperature. That's fine. but then you declare all your bool functions to take a float. Your bool functions should NOT take an argument. They should use the member variable which has been set. Do it one way or the other, not both.



Last edited on
Topic archived. No new replies allowed.