%3Cp%3E1.-%20Write%26nbsp%3Ba%26nbsp%3Bclass%26nbsp%3Bdeclaration%26nbsp%3Bfor%2
ID: 3548744 • Letter: #
Question
%3Cp%3E1.-%20Write%26nbsp%3Ba%26nbsp%3Bclass%26nbsp%3Bdeclaration%26nbsp%3Bfor%26nbsp%3Ba%26nbsp%3Bclass%26nbsp%3Bcan%26nbsp%3Bto%26nbsp%3Brepresent%26nbsp%3Ba%26nbsp%3Bcylindrical%26nbsp%3Baluminum%26nbsp%3Bcan.%26nbsp%3BObjects%26nbsp%3Bof%26nbsp%3Bthis%26nbsp%3Bclass%26nbsp%3Bshould%26nbsp%3Bknow%26nbsp%3Btheir%26nbsp%3Bown%26nbsp%3B(empty)%26nbsp%3Bweight%26nbsp%3Bin%26nbsp%3Bgrams%26nbsp%3Band%26nbsp%3Btheir%26nbsp%3Bdimensions%26nbsp%3B-base%26nbsp%3Bradius%26nbsp%3Band%26nbsp%3Bheight-%26nbsp%3Bin%26nbsp%3Bcentimeters.%26nbsp%3BThe%26nbsp%3Bclass%26nbsp%3Bshould%26nbsp%3Binclude%26nbsp%3Ba%26nbsp%3Bmember%26nbsp%3Bfunction%26nbsp%3Bnamed%26nbsp%3Bcapacity%26nbsp%3Bthat%2C%26nbsp%3Bgiven%26nbsp%3Bthe%26nbsp%3Bvolume%26nbsp%3B(cm%5E3)%26nbsp%3Bof%26nbsp%3B1%26nbsp%3Bgram%26nbsp%3Bof%26nbsp%3Ba%26nbsp%3Bproduct%26nbsp%3Bto%26nbsp%3Bbe%26nbsp%3Bcanned%2C%26nbsp%3Bcould%26nbsp%3Banswer%26nbsp%3Bthe%26nbsp%3Bquestion%26nbsp%3B%22How%26nbsp%3Bmany%26nbsp%3Bwhole%26nbsp%3Bgrams%26nbsp%3Bof%26nbsp%3Bthis%26nbsp%3Bproduct%26nbsp%3Bwill%26nbsp%3Bfit%26nbsp%3Bin%26nbsp%3Bthis%26nbsp%3Bcan%3F%22%26nbsp%3BDo%26nbsp%3Bnot%26nbsp%3Bforget%26nbsp%3Bto%26nbsp%3Binclude%26nbsp%3Bconstructors%2C%26nbsp%3Bone%26nbsp%3Bthat%26nbsp%3Btakes%26nbsp%3Bparameters%26nbsp%3Bfor%26nbsp%3Binitializaing%26nbsp%3Bcomponents%26nbsp%3Band%26nbsp%3Bone%26nbsp%3Bthat%26nbsp%3Bdoes%26nbsp%3Bnot.%26nbsp%3B%3Cbr%3E%3Cbr%3E2.-%26nbsp%3BImplement%26nbsp%3Bclass%26nbsp%3Bcan%26nbsp%3Bwhose%26nbsp%3Bdeclaration%26nbsp%3Byou%26nbsp%3Bwrote%26nbsp%3Bon%26nbsp%3Bquestion%26nbsp%3B1.%26nbsp%3BWrite%26nbsp%3Ba%26nbsp%3Bmain%26nbsp%3Bfunction%26nbsp%3Bthat%26nbsp%3Bprompts%26nbsp%3Bfor%26nbsp%3Band%26nbsp%3Binputs%26nbsp%3Ba%26nbsp%3Bcan%26nbsp%3Bobject%26nbsp%3Band%26nbsp%3Bthe%26nbsp%3Brepeatedly%26nbsp%3Binputs%26nbsp%3Bthe%26nbsp%3Bvolume%26nbsp%3Bof%26nbsp%3B1%26nbsp%3Bgram%26nbsp%3Bof%26nbsp%3Bvarious%26nbsp%3Bproducts%26nbsp%3Bto%26nbsp%3Bbe%26nbsp%3Bcanned.%26nbsp%3BDisplay%26nbsp%3Bhow%26nbsp%3Bmany%26nbsp%3Bwhole%26nbsp%3Bgrams%26nbsp%3Bof%26nbsp%3Beach%26nbsp%3Bproduct%26nbsp%3Bshould%26nbsp%3Bfit%26nbsp%3Bin%26nbsp%3Bthe%26nbsp%3Bcan.%3C%2Fp%3EExplanation / Answer
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <fstream>
#include <sstream>;
using namespace std;
class can
{
private:
public:
float weight;
float radius;
float height;
float volume;
can();
float capacity(float);
};
can::can()
{
weight = 0.0;
radius = 0.0;
height = 0.0;
}
float can::capacity(float density)
{
volume = (3.14)*(radius)*(radius)*(height);
return (volume/density);
}
int main()
{
can can_object;
string mat;
string output;
float den; float content;
cout << "Enter the weight of the can: ";
cin >> can_object.weight;
cout << " Enter the radius of the base: ";
cin >> can_object.radius;
cout << " Enter the height of the can: ";
cin >> can_object.height;
while(1==1)
{ cout << " Type the name of the material or type 'z' to see the output: ";
cin >> mat;
if (mat=="z")break;
output = output + mat;
cout << "Enter the volume of 1 gram of the material: ";
cin >> den;
content = can_object.capacity(den);
std::stringstream ss (stringstream::in | stringstream::out);
ss << content;
string mat = ss.str();
output = output + " " + mat + " ";
}
cout << endl<<output;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.