Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ×××××××××××××××
- Datamembers:
- -mysiLength
- -mysiWidth
- -mysiArea
- _______________
- +constructor
- +mysiArea getter
- +toString
- ×××××××××××××××
- */
- #include <iostream>
- using namespace std;
- #include <string>
- #include <sstream>
- #include <algorithm>
- class Rectangle
- {
- private:
- short mysiLength;
- short mysiWidth;
- long myliArea;
- short abs(short siArg)
- {
- if(siArg<0)
- siArg=-siArg;
- return siArg;
- }
- public:
- Rectangle(short siLength=0, short siWidth=0)
- {
- mysiLength=abs(siLength);
- mysiWidth=abs(siWidth);
- myliArea=mysiWidth*mysiLength;
- }
- long getArea()
- {
- return myliArea;
- }
- string toString()
- {
- stringstream ss;
- ss << myliArea << "=" << mysiLength << "*" << mysiWidth << endl;
- return ss.str();
- }
- };
- void io(short*, short*);
- void manage_Rectangle_arr(string, Rectangle * *, short*);
- int main()
- {
- Rectangle * * arr;
- short siArrayL=1;
- manage_Rectangle_arr("make array", arr, &siArrayL);
- //manage_Rectangle_arr("fill array", arr, &siArrayL);
- //manage_Rectangle_arr("get areas", arr, &siArrayL);
- //manage_Rectangle_arr("empty contents", arr, &siArrayL);
- manage_Rectangle_arr("delete array", arr, &siArrayL);
- }
- void io(short* siArg0, short*siArg1)
- {
- cout << "Length: ";
- cin >> *siArg0;
- cout << "Width: ";
- cin >> *siArg1;
- }
- void manage_Rectangle_arr(string strCommand, Rectangle * *arr, short *siArrayL)
- {
- if(strCommand=="make array")
- arr = new Rectangle * [ *siArrayL];
- if(strCommand=="fill array")
- for(short s=0; s< *siArrayL; ++s)
- arr[s]= new Rectangle(1, 1);
- if(strCommand=="get areas")
- for(short s=0; s< *siArrayL; ++s)
- cout << arr[s]->getArea();
- if(strCommand=="empty contents")
- for(short s=0; s< *siArrayL; ++s)
- delete arr[s];
- if(strCommand=="delete array")
- delete [] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement