Skip to content

Instantly share code, notes, and snippets.

@aa-ahmed-aa
Created July 2, 2018 13:26
Show Gist options
  • Save aa-ahmed-aa/956696d6e80a59fd532f55c22ea74442 to your computer and use it in GitHub Desktop.
Save aa-ahmed-aa/956696d6e80a59fd532f55c22ea74442 to your computer and use it in GitHub Desktop.
# include <iostream>
# include <string>
# include <fstream>
# include <vector>
# include <algorithm>
# include <exception>
# include <sstream>
using namespace std;
//adding function to the ostream and istream
//
//ostream &rightArrow(ostream &output)//remember ostream
//{
// output << "cool name man ----> ";
// return output;
//}
//
//istream &getname(istream &input)//remember istream
//{
// cout << "enter your name please" << endl;
// return input;
//}
//
//int main()
//{
// string name;
// cin >> getname >> name;
// cout << rightArrow << name<<endl;
//}
////stringstream
//# include <sstream>
//int main()
//{
// string number = "44";
//
// stringstream a;
// a << number;
// int input;
// a >> input;
// cout << input << endl;
// cout << ++input << endl;
// cout << number+"2" << endl;
//}
//string processing
//int main()
//{
// string a = "Ahmed Khaled";
// cout << a << endl;
//
// a.append(" Mohamed");
// cout << a << endl;
//
// a.insert(0, "my name is ");
// cout << a << endl;
//
// cout << a.substr(11)<<endl; //to substring the string from the passing number
//
// a.erase(0,11); //to delete astring
// cout << a << endl;
//
//}
//
////auto Flags
//int main()
//{
// auto flag = ios::showpoint ;
// cout.flags(flag);
// cout << 12.14 << endl;
// cout << 145.14 << endl;
// cout << 5478.542 << endl;
//}
//polymorphism
//class Person
//{
//public:
// virtual void display()
// {
// cout << "Hi from person " << endl;
// }
//};
//
//class Student : public Person
//{
//public:
// void display()
// {
// cout << "Hi from Studnet" << endl;
// }
//};
//
//class Formal :public Person
//{
//public:
// void display()
// {
// cout << "Hi from Former" << endl;
// }
//};
//
//void whoareyou(Person &a)
//{
// a.display();
//}
//
//
//int main()
//{
// Formal a;
// Student s;
// whoareyou(s);
//}
////operator overloading
//class H
//{
//public:
// int a;
// H(int f)
// {
// a = f;
// }
//
// void display()
// {
// cout << a << endl;
// }
//
// H operator+=(H f)
// {
// this->a += f.a ;
// return *this;
// }
//
//};
//
//int main()
//{
// H a(5);
// a.display();
// a += 5;
// a.display();
//}
//operator overloading ++ and --
//class ASD
//{
// int name;
//public:
// ASD(int n)
// {
// name = n;
// }
// void display()
// {
// cout << " name num is : " << name << endl;
// }
//
// ASD operator++()
// {
// name += 1;
// return *this; // to return the object
// }
//
// ASD operator--()
// {
// name -= 1;
// return *this;
// }
//};
//
//int main()
//{
// ASD a(85);
// a.display();
// ++a;
// a.display();
// --a;
// a.display();
//
//}
//operator overloading overloading braces ()
//class asd
//{
//private:
// int mark;
//public:
// asd(int m)
// {
// cout << "constructor is called" << endl;
// mark = m;
// }
//
// void whatisthat()
// {
// cout << "hey i got "<<mark<<" marks" << endl;
// }
//
// asd operator()(int mk)
// {
// cout << "operator is called " << endl;
// mark = mk;
// return *this;
// }
//};
//
//int main()
//{
// asd a(5);
// a.whatisthat();
// a(44);
// a.whatisthat();
//}
//inner class or nasted class
//class asd
//{
//public:
// string name;
// class asd2
// {
// public:
// string address;
// int hno;
// };
// asd2 a;
// void disp()
// {
// cout << name << " : " << a.address << " : " << a.hno << endl;
// }
//};
//int main()
//{
// asd a;
// a.name = "Ahmed";
// a.a.address = "Minia";
// a.a.hno = 10;
// a.disp();
//catch all the exceptions
//int main()
//{
// try
// {
// throw "runtime error";
// }
// catch (...) //that means all off exception or else exception than the upove
// {
// cout << "some error occured" << endl;
// }
//}
//inline key word in namespace
//namespace asd
//{
// namespace a
// {
// void display()
// {
// cout << "i am the A name space " << endl;
// }
// }
// namespace b
// {
// void display()
// {
// cout << "i am the B name space " << endl;
// }
// }
// inline namespace c
// {
// void display()
// {
// cout << "i am the C name space " << endl;
// }
// }
//}
//
//int main()
//{
// asd::display();
//}
//simple exception handling
//int main()
//{
// int a = 10, b = 0;
// int c ;
// try{
// if (b == 0)
// throw "divade by zero error";
//
// c = a / b;
// cout << c << endl;
// }
// catch (const char e[])
// {
// cout << "Exception occured" << endl << e << endl;
// }
//
//
//}
//virtual class
//class Animal
//{
//public:
// int age;
// Animal()
// {
// cout << "am aconstructor of animal" << endl;
// }
// void walk()
// {
// cout << "animal walks " << endl;
// }
//};
//
//
//class Tiger :virtual public Animal
//{
//public:
// Tiger()
// {
// cout << "constructor of Tiger" << endl;
// }
//};
//
//class Lion : virtual public Animal
//{
//public:
// Lion()
// {
// cout << "constructor of Lion" << endl;
// }
//};
//
//class Liger : public Tiger, public Lion
//{
//public:
// Liger()
// {
// cout << "constructor of Liger" << endl;
// }
//};
//
//int main()
//{
// Liger a;
// a.walk();
//}
//Call Function from aderived class
//class Person
//{
//public:
// void introduce()
// {
// cout << "hey from person " << endl;
// }
//};
//
//
//class Student :public Person
//{
//public:
// void introduce()
// {
// cout << "hey from student" << endl;
// }
//};
//
//void whoisthis(Person p)
//{
// p.introduce();
//}
//
//int main()
//{
// Student a;
// a.introduce();
// whoisthis(a);
//}
//call constructor from aderived class
//class Father
//{
//protected:
// int height;
//public:
// Father()
// {
// cout << "constructor of Father is Called " << endl;
// }
//};
//
//class Mother
//{
//protected:
// string skincolor;
//public:
// Mother()
// {
// cout << "constructor of Mother is Called " << endl;
// }
//};
//
//class Child : public Father , public Mother
//{
//public:
// Child(int x, string color) : Father(), Mother()
// {
// height = x;
// skincolor = color;
// cout << "child class Constructor" << endl;
// }
// void display()
// {
// cout << "heigth is : " << height << " and skincolor is "<<skincolor << endl;
// }
//};
//
//int main()
//{
// Child a(24,"white");
// a.display();
//}
////Virtual
//class Person
//{
//public:
// virtual void introduce()
// {
// cout << "hi from person " << endl;
// }
//
//};
//
//class Student :public Person
//{
//public:
// void introduce()
// {
// cout << " hi from student " << endl;
// }
//};
//
//
//class Gstudent : public Student
//{
//public:
// void introduce()
// {
// cout << " hi from Graduated student " << endl;
// }
//};
//
//void whoisthis(Person &p) //virtual function
//{
// p.introduce();
//}
//
//int main()
//{
// Person a;
// Student s;
// Gstudent d;
//
// whoisthis(a);
// whoisthis(s);
// whoisthis(d);
//}
//static key word
//void display()
//{
// static int counter = 0;
// cout << "display function called " <<++counter << " time"<< endl;
//}
//
//int main()
//{
// display();
// display();
// display();
// display();
// display();
// display();
// display();
//}
//pure virtual function
//class Person
//{
//public:
// virtual void introduce() =0;
//
//};
//
//void Person::introduce()
//{
// cout << "hi from person" << endl;
//}
//
//class Student :public Person
//{
//public:
// void introduce()
// {
// cout << "hi iam astudent " << endl;
// Person::introduce();
// }
//
//};
//
//int main()
//{
// Student a;
// a.introduce();
//}
//protected in class
//class Person
//{
//protected :
// string name;
//public:
// void setname(string name)
// {
// this->name = name;
// }
//
//};
//
//class Student : public Person
//{
//public:
// void display()
// {
// cout << name << endl;
// }
//};
//
//int main()
//{
// Student a;
// a.setname("ahmed");
// a.display();
//}
//copy constructors
//class Person
//{
//public:
// string *name;
// int age;
// Person(string name, int age)
// {
// this->name = new string(name);
// this->age = age;
// }
//
// Person(const Person &p)
// {
// name = new string(*p.name);
// age = p.age;
// cout << "copy constructor is called " << endl;
// }
//
// void changeNameandAge(string name, int age)
// {
// *(this->name) = name;
// this->age = age;
// }
//
// void introduce()
// {
// cout << "hey i am " << *name << " and i am " << age << " years old" << endl;
// }
//};
//
//int main()
//{
// Person a("ahmed", 20);
// a.introduce();
//
// Person d=a;
// d.introduce();
//
// a.changeNameandAge("ahmed khaled", 222);
// a.introduce();
// d.introduce();
//}
//some iomanip default
//int main()
//{
// cout.precision(5);
// cout << 123.456 << endl;
//
// cout.fill('*');
// cout.width(10);
// cout << "hi" << endl;
// cout.width(10);
// cout << "my" << endl;
//
// cout.setf(ios::left);
// cout.width(10);
// cout << "hi" << endl;
// cout.width(10);
// cout << "my" << endl;
//}
////predefined macros
//int main()
//{
// /*
// __LINE__
// __FILE__
// __DATE__
// __TIME__
// __cplusplus
// */
//
// cout << "current line is : "<<__LINE__ << endl;
// cout << "current file is : " << __FILE__ << endl;
// cout << "date is : " << __DATE__ << endl;
// cout << "Time is : "<<__TIME__ << endl;
// cout << "standatrd c++ confirming : " << __cplusplus << endl;
//
//#line 1000 "ahmed.txt"
// cout << "current line is : " << __LINE__ << endl;
// cout << "current file is : " << __FILE__ << endl;
//}
//overiding maters of derived class
//class Person
//{
//public:
// void introduce()
// {
// cout << "hi iam aperson" << endl;
// }
//};
//
//class Student :public Person
//{
//public:
// void introduce()
// {
// cout << "hi iam a student" << endl;
// }
//};
//
//int main()
//{
// Student a;
// a.introduce();
//}
//operator overloading
//class Mark
//{
//private :
// int inmark;
// int exmark;
//public:
// Mark()
// {
// inmark = 0;
// exmark = 0;
// }
//
// Mark(int im, int em)
// {
// inmark = im;
// exmark = em;
// }
//
// void display()
// {
// cout << inmark << endl << exmark << endl;
// }
//
// Mark operator++()
// {
// Mark temp;
// temp.inmark = inmark + 10;
// temp.exmark = exmark + 10;
// return temp;
// }
//
//};
//
//int main()
//{
// Mark m1(10,20);
//
// Mark m3 = m1++;
// m3.display();
//
//}
//default constructor with and without parameter
//class asd
//{
//private:
// string name;
//
//public:
// asd()
// {
// name = "noname";
// cout << "consttructor !1" << endl;
// }
// asd(string a)
// {
// name = a;
// cout << "constructor !2" << endl;
// }
// void display()
// {
// cout << "your name is :"<<name << endl;
// }
//};
//
//
//int main()
//{
// asd a;
// a.display();
// asd a("ahmed");
// a.display();
//}
//nested try catch
//int main()
//{
// try
// {
// try
// {
// throw "a character exception" ;
// }
// catch (const char *e)
// {
// cout << "character type in inner block -->" << e << endl;
// throw;
// }
//
// }
// catch (const char *e)
// {
// cout << "character type in outer block" << e << endl;
// }
// catch (...)
// {
// cout << "unexpected type in outer block -->" << endl;
// }
//
//
//}
//name space and nasted namespaces
//namespace one
//{
// int x ;
// namespace asd
// {
// void display()
// {
// cout << "X is "<<x << endl;
// }
// }
//}
//
//int main()
//{
// one::x = 100;
// one::asd::display();
//}
//Multiple inheritanse
//class Father
//{
//public:
// int height;
// void askFather()
// {
// cout << "am your father ask me what you want" << endl;
// }
//
//
//};
//
//class Mother
//{
//public:
// string skincolor;
// void askMOther()
// {
// cout << "am your mother what you want" << endl;
// }
//};
//
//class Child : public Mother, public Father
//{
//public:
// void askParents()
// {
// cout << "am asking my parents " << endl;
// }
// void setcolorandheight(string icolor, int iheight)
// {
// skincolor = icolor;
// height = iheight;
// }
//
// void display()
// {
// cout << "height is " << height << "and color is " << skincolor << endl;
// }
//};
//
//int main()
//{
// Child asd;
// asd.setcolorandheight("white", 6);
// asd.display();
// asd.askFather();
// asd.askMOther();
//}
//the iomanip libary
//int main()
//{
// cout << "hi" << endl;
// cout << hex << 100 << endl; // to write the number as hexadecimal
//
// cout << setw(10)<< "ahmed" << endl;
// cout << "shetty" << endl;
//}
////generic function & template function
//template<typename T>void display(T x, T y)
//{
// cout << x << " and " << y << endl;
//}
//
//template<class T>T maxi(T x, T y)
//{
// return (x >= y) ? x : y;
//}
//
//int main()
//{
// display(20,30);
// display("ahmed", "khaled");
// display(12.36, 56.78);
//
// cout << maxi(5,7) << endl;
// cout << maxi("ahmed", "khaled") << endl;
//}
//templates with class
//template <class Type1 , class Type2>
//class MyClass
//{
//private:
// Type1 p1;
// Type2 p2;
// int counter;
//
//public:
// MyClass(Type1 x, Type2 y)
// {
// p1 = x;
// p2 = y;
// counter = 100;
// }
//
// void display()
// {
// cout << "i got p1 = " << p1 << " and p2 " << p2 << " and counter is " << counter << endl;
// }
//};
//
//int main()
//{
// MyClass <int, string> asd1(5,"ahmed");
// MyClass <float, float> asd2(22.36, 66.241);
//
// asd1.display();
// asd2.display();
//
//}
//Macros
//# define ABS(number) {(number<0) ? -number : number}
//
//int main()
//{
// int a=ABS((-5));
// cout << a << endl;
//
//}
//friend function
//class Human
//{
//private:
// string name;
// int age;
//public:
// Human(string iname, int iage)
// {
// name = iname;
// age = iage;
// }
// void tellme()
// {
// cout << name << endl<<age<<endl;
// }
// friend void display(Human man);
//};
//
//void display(Human man)
//{
// cout << man.name << endl << man.age << endl;
//}
//
//int main()
//{
// Human m("ahmed", 20);
// display(m);
// return 0;
//}
//tellp() tellg seekp() seekg()
//int main()
//{
// fstream a("in.txt",ios::in | ios::out | ios::trunc);
// if (!a)
// {
// cout << "can't open" << endl;
// }
// else
// {
// cout << a.tellp() << endl;
// cout << a.tellg() << endl;
// a.seekp(2);
// cout << a.tellp() << endl;
// cout << a.tellg() << endl;
// }
//}
//constructor and destructor
//class Human
//{
//private:
// string name;
// int age;
//public:
// Human(string iname, int iage) :name(iname), age(iage)
// {}
//
// void display()
// {
// cout << "hi i am "<<name<<" and i am "<<age<<"years old" << endl;
// }
//
// ~Human()
// {
// name = "";
// age = 0;
// cout << "all memory are released :" << endl;
// }
//};
//
//int main()
//{
// Human a("ahmed", 20);
// a.display();
//}
////#ifdef and #ifndef
//# define Ahmed 1
//int main()
//{
//#ifdef Ahmed
// cout << "hi Ahmed" << endl;
//#endif
//
//#ifndef Ahmed //if not define
// cout << "who r u" << endl;
//# endif
//
//}
//file.write and write class object
//class student
//{
//private:
// string name;
// int age;
//public:
// student()
// {
// name = "";
// age = 0;
// }
// student(string name, int age)
// {
// this->name = name;
// this->age = age;
// }
// void show()
// {
// cout << "your name is :" << name <<endl<< "your age is " << age << endl<<endl;
// }
//};
//
//
//int main()
//{
// fstream a("File.txt", ios::in | ios::out );
// if (!a.is_open())
// {
// cout << "can't open this file::::" << endl;
// }
// else
// {
// student s1("ahmed", 20);
// //write the data to file
// a.write((char *)&s1, sizeof(student));
// a.seekp(0);
//
// //read the data from the file
// student s2;
// a.read((char *)&s2, sizeof(student));
//
// s1.show();
// s2.show();
// }
//
//}
//#define and #undef
//# define Name "Ahmed"
//int main()
//{
//
//#ifdef Name
// cout << "your name is " << Name<<endl;
//#endif // Name
//
//#undef Name
//
//#ifdef Name
// cout << "your name is " << Name;
//#endif // Name
//
//}
//Exception handling------------------------
//int main()
//{
// int a, b, c;
// cin >> a >> b;
//
// try {
// if (b == 0)
// throw runtime_error("hi error");
// c = a / b;
// cout << c << endl;
// }
// catch (runtime_error(&error)){
// cout << "exception occured" << endl;
// cout << error.what()<<endl;
// }
//
// return 0;
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment