fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #define ld long double
  4. #define ull unsigned long long
  5. #define ll long long
  6. #define BMW_3nn_3nn_3nn \
  7. ios::sync_with_stdio(0); \
  8. cin.tie(0); \
  9. cout.tie(0);
  10. #define sz(s) (int)s.size()
  11. #define all(v) v.begin(),v.end()
  12. #define rall(v) v.rbegin(),v.rend()
  13. #define endl "\n"
  14. using namespace std;
  15. /*class point{
  16. public:
  17.   int hr, min, sec ;
  18. };*/
  19. /*class point2 {
  20.   private:
  21.   int x, y;
  22.   public:
  23.   void set_x(int n) {
  24.   if (n>24 or n<0) cout<<"Error"<<endl;
  25.   else x=n;
  26.   }
  27.   void set_y(int m) {
  28.   if (m>=60 or m<0) cout<<"Error"<<endl;
  29.   else y=m;
  30.   }
  31.   int get_x() {
  32.   return x;
  33.   }
  34.   int get_y() {
  35.   return y;
  36.   }
  37. };*/
  38. /*class student {
  39.   private:
  40.   char name[100];
  41.   int id;
  42.   public:
  43.   student() {
  44.   cout << "object created"<< endl;
  45.   }
  46.   void set_name_id(char n[] , int p) {
  47.   strcpy(name, n);
  48.   id = p;
  49.   }
  50.   ~student() {
  51.   cout << "object deleted"<< endl;
  52.   }
  53.   void display() {
  54.   cout << name << "\t"<< id << endl;
  55.   }
  56. };
  57. /*void f(student s) {
  58.   student s1;
  59.   s1=s;
  60.   s.set_name_id("sami",30);
  61.   s.display();
  62.   s1.display();
  63. }*/
  64. /*class Dog {
  65.   private:
  66.   string name;
  67.   int wight ;
  68.   public:
  69.   Dog() {
  70.   cout << "object created by empty constructor" << endl;
  71.   }
  72.   Dog(const Dog& d) {
  73.   name = d.name ;
  74.   wight = d.wight;
  75.   }
  76.   Dog(string n, int w): name(n), wight(w) {
  77.   cout << "object created by paramatreize constuctor " << endl;
  78.   }
  79.   void display() const
  80.   {
  81.   cout << "hello dog" << endl;
  82.   }
  83.   void set_name_wight(string n , int w) {
  84.   name=n;
  85.   wight = w;
  86.   }
  87.   int get_wight() const
  88.   {
  89.   return wight;
  90.   }
  91.   string get_name() const
  92.   {
  93.   return name ;
  94.   }
  95.   ~Dog() {
  96.   cout << "object deleted" << endl;
  97.   }
  98. };*/
  99. /*class Distence {
  100.   private:
  101.   int feet ;
  102.   float inshes ;
  103.   public:
  104.   Distence(): feet (0), inshes (0) {
  105.   }
  106.   Distence (int f ,float i ) : feet (f), inshes (i) {}
  107.   Distence operator + (Distence d) {
  108.   int f = feet + d.feet;
  109.   float i = inshes + d.inshes;
  110.   if (i>=12) {
  111.   i = i + 12;
  112.   f++;
  113.   }
  114.   return Distence(f,i);
  115.   }
  116.   Distence operator - (Distence d) {
  117.   int f;float i ;
  118.   if (feet >= d.feet) {
  119.   f = feet - d.feet;
  120.   }
  121.   if (inshes >= d.inshes) {
  122.   i = inshes - d.inshes;
  123.   }
  124.   if (i>=12) {
  125.   f += int (i / 12);
  126.   i = i - (i/12);
  127.   }
  128.   return Distence(f,i);
  129.   }
  130.   void display() {
  131.   cout << feet << "\t" << inshes << endl;
  132.   }
  133.   };*/
  134. /*class bankaccount {
  135.   private:
  136.   int accountnumber;
  137.   double balance;
  138.   public:
  139.   bankaccount():accountnumber(0),balance(0) {
  140.   }
  141.   bankaccount(int d , double a): accountnumber(d ), balance(a) {
  142.   }
  143.   void set_accountnumber(int d) {
  144.   accountnumber = d;
  145.   }
  146.   void set_balance(double a) {
  147.   balance = a;
  148.   }
  149.   int get_accountnumber() {
  150.   return accountnumber;
  151.   }
  152.   double get_balance() {
  153.   return balance;
  154.   }
  155.   void deposit(double a) {
  156.   if (a > 0) {
  157.   balance += a;
  158.   } else {
  159.   cout << "Invalid deposit amount !" << endl;
  160.   }
  161.   }
  162.   void withdraw(double a) {
  163.   if (a > 0&& balance >= a) {
  164.   balance -= a;
  165.   }else {
  166.   cout << "Insufficient funds or Invalid amount !" << endl;
  167.   }
  168.   }
  169.   bankaccount (const bankaccount &a) {
  170.   accountnumber = a.accountnumber;
  171.   balance = a.balance;
  172.   }
  173.   bankaccount operator+(const bankaccount& b) {
  174.   bankaccount temp;
  175.   temp.set_balance(balance + b.balance);
  176.   return temp;
  177.   }
  178.   bankaccount operator-(const bankaccount& b) {
  179.   bankaccount temp;
  180.   temp.set_balance(abs(balance - b.balance));
  181.   return temp;
  182.   }
  183.   void display() {
  184.   cout <<"id account "<< accountnumber << " amount acount " << balance << endl;
  185.   }
  186.  };*/
  187. class animal {
  188. private:
  189. string name;
  190. int age ;
  191. public:
  192. animal(string n , int a): name(n), age(a) {}
  193. void sound() {
  194. cout << "the animal's name makes sound ";
  195. }
  196. void displayinfo() {
  197. cout << "name is " << name <<" age is "<< age << endl;
  198. }
  199. };
  200. class dog : public animal {
  201. private:
  202. string breed;
  203. public:
  204. dog (string n , int a,string b): animal(n,a), breed(b) {}
  205. void sound() {
  206. cout << "the dog's breed is milk "<< endl;
  207. }
  208. void displayinfo() {
  209. animal::displayinfo();
  210. cout << " breed is " << breed << endl;
  211. }
  212. };
  213. int main() {
  214. BMW_3nn_3nn_3nn ;
  215. /*
  216.   point t;
  217.   cin>> t.hr;
  218.   point t2 ;
  219.   cin>> t2.hr;
  220.   if (t.hr > t2.hr ) cout << "time 1 is max "<<endl;
  221.   else cout << "time 2 is max "<<endl;
  222.   */
  223. /* point2 t;
  224.   int n,m; cin>> n >>m;
  225.   t.set_x(n);
  226.   t.set_y(m);
  227.   n=t.get_x();
  228.   m=t.get_y();
  229.   point2 t2 ;
  230.   int n1,m1;cin>>n1>>m1 ;
  231.   t2.set_x(n1);
  232.   t2.set_y(m1);
  233.   n1=t2.get_x();
  234.   m1=t2.get_y();
  235.   if(n1>n) cout << "time 2 is max "<<endl;
  236.   else if(n1<n) cout << "time 1 is max "<<endl;
  237.   else {
  238.   if(m>m1) cout << "time 1 is max "<<endl;
  239.   else if(m<m1) cout << "time 2 is max "<<endl;
  240.   }
  241.   student st1,st2;
  242.   st1.set_name_id("ahmed",123);
  243.   st2.set_name_id("ali",124);
  244.   cout << "going to fun\n";
  245.   f(st1);
  246.   cout << "back from fun\n";
  247.   st1.display();*/
  248. /*Dog d("roi",30);
  249.   d.set_name_wight("roi",30);
  250.   d.display();
  251.   cout << d.get_name()<<" " << d.get_wight() << endl;
  252.   /*std::vector<dog> dogs(6);
  253.   for (const dog& du : dogs)
  254.   {
  255.   du.display();
  256.   }*/
  257. /*Distence d1(5,9),d2(5,7);
  258.   Distence d3 = d1 + d2;
  259.   Distence d4 = d1 - d2;
  260.   d1.display();
  261.   d2.display();
  262.   d3.display();
  263.   d4.display();*/
  264. /* bankaccount a1(123,230.0),a2(1234,300.0),a3(12345,0),a4;
  265.   a4=a3;
  266.   a3=a1 - a2 ;
  267.   a3.set_accountnumber(a4.get_accountnumber());
  268.   a3.display();*/
  269. dog baby("baby",10,"breed");
  270. baby.displayinfo();
  271. baby.sound();
  272. animal dog1("dog1",15);
  273. dog1.displayinfo();
  274. dog1.sound();
  275. return 0;
  276. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
name is baby age is 10
  breed is breed
the dog's breed is milk 
name is dog1 age is 15
the animal's name makes sound