Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Square{
- double side,area;
- public:
- Square(){
- side=0;area=0;
- }
- Square(double a){
- if(a<0) throw -1;
- side=a;area=a*a;
- }
- void print(){
- cout<<"Square: side= "<<side<<"area= "<<area<<"\n";
- }
- Square& set_side(double a){
- if(a<0) throw -1;
- side=a;area=a*a;
- return *this;
- }
- };
- int main(){
- Square s1;
- s1.print();
- s1.set_side(2);
- s1.print();
- Square s2(2);
- try{
- s2.set_side(-555);
- }
- catch(...){
- cerr<<"Wyjatek\n";
- }
- try{
- Square s3(-5);
- }
- catch(...){
- cerr<<"Wyjatek\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement