Beginner c++ programmer: Stuck writing a class -
i have write program exercise in classes, i'm lost. have bit of experience programming in java, switch c++ syntax confusing me quite bit.
the prompt is: write definition of class , swimmingpool , implement proper-ties of swimming pool. class should have instance variables store length (in feet), width (in feet), depth (in feet), rate (in gallons per minute) @ water filling pool, , rate (in gallons per minute) @ water draining pool. add appropriate constructors initialize instance variables. add member functions following: determine amount of water needed fill empty or partially filled pool, determine time needed or partially fill or empty pool, , add or drain water specific amount of time.
i getting several build errors. understand have right not complete. here progress far.
#include <iostream> using namespace std; int main() { swimmingpool myswimmingpool; int length, width, depth, ratetofill, ratetodrain; cout << "pool data: " << endl; cout << myswimmingpool.getpooldata(5, 12,6) << endl; } class swimmingpool { public: int getpooldata(int, int, int); int getamountofwater(); int gettime(); int incrementwater(double time); int decrementwater(double time); int poolcapacity(); swimmingpool(); swimmingpool(int l, int w, int d, int ratefill, int ratedrain); private: int length; int width; int depth; int ratetofill; int ratetodrain; }; swimmingpool::swimmingpool() { length = 0; width = 0; depth = 0; ratetofill = 0; ratetodrain = 0; } swimmingpool::swimmingpool(int l, int w, int d, int ratefill, int ratedrain) { length = l; width = w; depth = d; ratetofill = ratefill; ratetodrain = ratedrain; } int swimmingpool::getpooldata(int l, int w, int d) { length = l; width = w; depth = d; cout << "length: " << l << endl; cout << "width: " << w << endl; cout << "depth: " << d << endl; } int swimmingpool::getamountofwater() { return (length * width * depth); } int swimmingpool::gettime() { return getamountofwater() / ratetofill; } int swimmingpool::incrementwater(double time) { return ratetofill * time; } int swimmingpool::decrementwater(double time) { return ratetodrain * time; }
if program return type of functions not correct. please see modified code.
#include <iostream> using namespace std; class swimmingpool { public: void getpooldata(int, int, int); int getamountofwater(); double gettime(); double incrementwater(double time); double decrementwater(double time); int poolcapacity(); swimmingpool(); swimmingpool(int l, int w, int d, int ratefill, int ratedrain); private: int length; int width; int depth; int ratetofill; int ratetodrain; }; swimmingpool::swimmingpool() { length = 0; width = 0; depth = 0; ratetofill = 0; ratetodrain = 0; } swimmingpool::swimmingpool(int l, int w, int d, int ratefill, int ratedrain) { length = l; width = w; depth = d; ratetofill = ratefill; ratetodrain = ratedrain; } //if function not return value return type should void void swimmingpool::getpooldata(int l, int w, int d) { length = l; width = w; depth = d; cout << "length: " << l << endl; cout << "width: " << w << endl; cout << "depth: " << d << endl; } int swimmingpool::getamountofwater() { return (length * width * depth); } double swimmingpool::gettime() { return getamountofwater() / ratetofill; //this value double not int. if convert double int data maybe loss } double swimmingpool::incrementwater(double time) { return ratetofill * time; //this value double not int. if convert double int data maybe loss } double swimmingpool::decrementwater(double time) { return ratetodrain * time; //this value double not int. if convert double int data maybe loss } int main() { swimmingpool myswimmingpool; //you don't need variables //int length, width, depth, ratetofill, ratetodrain; cout << "pool data: " << endl; myswimmingpool.getpooldata(5, 12,6); return 0; }
Comments
Post a Comment