Question: C++ Implementing classes program. I'm getting a few errors in my program. Chemical.h:9:2: error: string does not name a type string name; ^ Chemical.h:16:18: error:
C++ Implementing classes program.
I'm getting a few errors in my program.
Chemical.h:9:2: error: string does not name a type string name; ^ Chemical.h:16:18: error: expected ) before n Chemical(string n, double m, double c); ^ Chemical.cpp:8:1: error: prototype for Chemical::Chemical(std::string, double, double) does not match any in class Chemical Chemical::Chemical(string n, double m, double c) ^ In file included from Chemical.cpp:4:0: Chemical.h:6:7: error: candidates are: constexpr Chemical::Chemical(Chemical&&) class Chemical { ^ Chemical.h:6:7: error: constexpr Chemical::Chemical(const Chemical&) Chemical.h:6:7: error: Chemical::Chemical() Chemical.cpp: In function double applyEnergyDifference(double): Chemical.cpp:19:3: error: temperature was not declared in this scope temperature = temperature + (q/(c*m)); ^ Chemical.cpp:19:35: error: c was not declared in this scope temperature = temperature + (q/(c*m)); ^ Chemical.cpp:19:37: error: m was not declared in this scope temperature = temperature + (q/(c*m)); ^ Chemical.cpp:22:2: error: control reaches end of non-void function [-Werror=return-type] } ^
Here's my code:
// main.cpp // // driver for working with a few chemicals
#include
using namespace std;
int main() { cout
//TODO: create a Chemical for water here! Chemical(h20, 100, 4,184);
cout
// TODO: call the applyEnergyDifference function to apply 1000.0 joules of energy! waterTemp = applyEnergyDifference(1000.0);
cout
cout
//TODO: create a Chemical for hydrogen chloride here! Chemical(hcl, 100, 0.7981);
cout
//TODO: call the applyEnergyDifference function to absorb 1000.0 joules of energy! hydrogenChlorideTemp = applyEnergyDifference(1000.0); cout
//Chemical.h
//Header for homework 06
#include
#pragma once
class Chemical {
private:
string name;
double mass;
double specificHeatCapacity;
double temperature;
public:
Chemical(string n, double m, double c);
double applyEnergyDifference(double q);
};
//Chemical.cpp
#include
#include
#include "Chemical.h"
using namespace std;
Chemical::Chemical(string n, double m, double c)
{
name = n;
mass = m;
specificHeatCapacity = c;
temperature = 0.0;
}
double applyEnergyDifference(double q)
{
temperature = temperature + (q/(c*m));
return temperature;
}


Go into main.cpp (already supplied) and add in the necessary code to create two chemicals with the following properties; their variable names will respectively be h20 and hcl.
a. water m = 100 c = 4.184 b. hydrogen chloride i. m = 100 ii. c = 0.7981
Task We want to write a program that uses classes to implement the heating and cooling of substances. We need a formula first: This equation tells us that the energy expelled or absorbed (Q, joules) is equal to the specific heat capacity (c, joules/(Celsius grams)) times mass (grams) times the change in temperature (Celsius). We want to expand and rearrange the equation a bit to achieve the following formula: Here, TE and T,are the final and initial temperatures of the substance. Given that for a specified substance, mass of that substance, and initial temperature, we can compute the new temperature by applying some energy difference (Q). Thus, we want to create a class to represent some sample. Our class should contain information to represent T, c, and m. We will have functions for the constructor and applying some energy differential to the chemical
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
