446,159 Members | 938 Online Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

# help with classes

 P: 8 hey guys, this is my assignment but i have no godly idea where to start. can anyone help? the assignment: A stock tank is a metal or plastic tank that ranchers and farmers use to provide water for their livestock. The tanks are usually made of metal or plastic, and come in three basic shapes; rectangular, oval, and circular. The rectangular and circular tanks are shaped as you expect, but the oval tank is actually a rectangle with ½-circles on each end. In this program, you are going to write a StockTankCalculator class that can be used to calculate the volume of a stock tank. Your calculator class will work with all 3 types of tanks. Given the shape of the tank, pertinent dimensions, the calculator can tell you how many gallons of water it will hold (completely full) as well as if given a percentage of the tank capacity will report the resultant number of gallons. The class should look like this and have these methods. Do not cout << anything from within the class. The gets and sets should be named using get and set in the name. You should use either floats or doubles for capacity values. class StockTankCalculator { private: //what is all the data that the calculator needs? public: StockTankCalculator(); set function for shape of the tank three set function for pertinent data for all three tank shapes get function for total capacity of tank get function, give a percentage value of total capacity, i.e. 50%, 75%, etc. string getTankData() //returns a string that describes the type of tank and its dimensions }; The StockTankCalculator has a default constructor that sets the tank to circular type, with diameter of 72 and depth of 24. Pertinent data that youll need or assumptions to use: 1) dimensions of the tanks are in whole inches, 2) there are 231 cubic inches per gallon of water, 3) total capacity of the tank has the water level at the very top. Your main method should write a header to the screen, and then create one StockTankCalculator object. Then present the user with the choice so that he may calculate the various tank sizes and capacities. Write all capacities in floating point data to two decimal places of accuracy. thanks guys! Jun 16 '06 #1
7 Replies

 Expert Mod 5K+ P: 8,916 Start by filling in the private data that you think the class will need, then proceed to implementing the function to set, manipulate and get this data. Jun 16 '06 #2

 P: 8 i meant help with coding...... Jun 17 '06 #3

 Expert Mod 5K+ P: 8,916 That is help with the coding, if you are looking for someone to do your assignment for you then you will have to find someone else. One the other hand if you want to attempt a solution yourself and then post it here then I will help you iron out any mistakes. When posting code try to post compilable units that you have already compiled and where possible eliminated any compile errors and warnings, if you can't eliminate a particular error/warning because you do not understand what is causing it then post the code and the error message and the code line it is happening on. So you should start by defining the class and you should start the class by defining the data that the class contains. Then you should define your function prototypes and then you should implement the functions. You know the starting data because the assignment basically gives it to you, you need to store the shape and dimensions of the tank and you know what functions you need because that is also given by the assignment. So write you class definition and once you have completed that start on coding the methods. Jun 17 '06 #4

 P: 8 Heres what I have after working on it this weekend. I have a bunch of errors and i started commenting out stuff to try to get it to compile. I finally got it to compile but now i have three linking errors. The prob is GetTankData() but i am stuck. thanks driver.cpp [PHP]#include "stocktank.h" #include #include using namespace std; void WriteHeader(); int main() { int ans; WriteHeader(); StockTank Calculator; //Calculator.SetTankDataCircle(int diam=72, int d=24); do { string info; cout << "Stock Tank Calculator"<> ans; cout << '\n'; switch(ans) { case 1: cout << "Stock Tank Shape Screen " << endl; cout << "Enter a tank type: " << endl; cout << "1. Circle" << endl; cout << "2. Rectangle" << endl; cout << "3. Oval" << endl; cout << "4. Return "<< endl; int ansshape; cin >> ansshape; switch (ansshape) { case 1: Calculator.SetTankShape(ansshape); //Calculator.SetTankDataCircle(); //Calculator.GetTankCapacity(); case 2: Calculator.SetTankShape(ansshape); //Calculator.SetTankDataRectangle(); //Calculator.GetTankCapacity(); } case 2: cout.setf(ios::fixed); cout.precision(2); info=Calculator.GetTankData(); cout << info; break; case 3: Calculator.GetTankPercent(); break; case 4: break; default: cout << "You must enter a valid response!" << endl< #include #include using namespace std; double pi=3.14; StockTank::StockTankCalculator() { //hape="circular"; //diam=72; //d=24; GetTankCapacity(); GetTankData(); } void StockTank::SetTankShape(int s) { if (s=1) { shape="circular"; //SetTankDataCircle(); } else if (s=2) { shape="rectangular"; //SetTankDataRectangle(); } else if (s=3) { shape="oval"; } } void StockTank::SetTankDataCircle() { int diameter; int depth; shape="circlular"; diameter=diam; depth=d; r=diam/2; StockTank::GetTankCapacity(); } void StockTank::SetTankDataCircle(int diam, int d) { int diameter; int depth; shape="circlular"; diameter=diam; depth=d; r=diam/2; //StockTank::GetTankCapacity(); } void StockTank::SetTankDataRectangle() { int length=0, width=0, height=0; cout << "You selected a " << shape << " stock tank." << endl; cout << "Please enter length of rectangle: " << endl; cin >> length; cout << "Please enter width of rectangle: " << endl; cin >> width; cout << "Please enter height of rectangle: " << endl; cin >> height; l=length; w=width; h=height; //StockTank::GetTankCapacity(); } float StockTank::GetTankCapacity() { int tanktype=0; switch (tanktype) { case 1: vol=pi*(pow(r,2))*d; totcapgal=vol/231; break; case 2: vol=l*w*h; totcapgal=vol/231; break; default: break; } return totcapgal; } float StockTank::GetTankPercent() { cout << "Enter a percentage in whole numbers (ex: 25 = 25%) "; cin >> percap; totcapper=(totcapgal*percap)*.01; cout << "The capacity of the " << shape << " tank at " << percap << "% is " << totcapper << endl << endl; return totcapper; } string GetTankData() { string data; //data=shape + diam + d+ totcapgal; //cout.setf(ios::fixed); //cout.precision(2); //cout << "The Stock Tank type is " << shape << endl; //cout << "The tank dimensions are: " << diam <<"\" by " << d << "\"."< using namespace std; class StockTank { private: int l,w,h,d,r,diam,percap; string shape; float vol; float totcapgal,totcapper; public: StockTankCalculator(); void SetTankShape(int s); void SetTankDataCircle(); void SetTankDataCircle(int diam, int d); void SetTankDataRectangle(); //void SetTankDataOval(); float GetTankCapacity(); float GetTankPercent(); string GetTankData(); }; #endif [/PHP] Jun 18 '06 #5 