diff --git a/C++/44_cppBeginners.cpp b/C++/44_cppBeginners.cpp new file mode 100644 index 0000000..c2ea264 --- /dev/null +++ b/C++/44_cppBeginners.cpp @@ -0,0 +1,46 @@ +//This is Sally.h file +#ifndef SALLY_H +#define SALLY_H + +class Sally +{ + public: + Sally(); + void printShiz(); + void printShiz2() const; + protected; + private; +}; + +#endif //SALLY_H + +//This is Sally.cpp file +#include "Sally.h" +#include +using namespace std; + +Sally::Sally() +{ +} + +void Sally::printShiz() +{ + cout << "i am a regular function"< +#include "Sally.h" +using namespace std; + +int main(){ + Sally salObj; + salObj.printShiz(); + + const Sally constObj; + constObj.printShiz2(); +} \ No newline at end of file diff --git a/C++/45_cppBeginners.cpp b/C++/45_cppBeginners.cpp new file mode 100644 index 0000000..fe95650 --- /dev/null +++ b/C++/45_cppBeginners.cpp @@ -0,0 +1,40 @@ +//This is Sally.h file +#ifndef SALLY_H +#define SALLY_H + +class Sally +{ + public: + Sally(int a,int b); + void print(); + private: + int regVar; + const int constVar; +}; + +#endif //SALLY_H + +//This is Sally.cpp file +#include "Sally.h" +#include +using namespace std; + +Sally::Sally(int a,int b) +:regVar(a), +constVar(b) +{ +} + +void Sally::print(){ + cout << "regular var is: " << regVar << "const varible is :" << constVar < +#include "Sally.h" +using namespace std; + +int main() +{ + Sally so(3,87); + so.print(); +} \ No newline at end of file diff --git a/C++/46_&47_cppBeginners.cpp b/C++/46_&47_cppBeginners.cpp new file mode 100644 index 0000000..88c2839 --- /dev/null +++ b/C++/46_&47_cppBeginners.cpp @@ -0,0 +1,82 @@ +//This is Birthday.h file +#ifndef BIRTHDAY_H +#define BIRTHDAY_H + +class Birthday +{ + public: + Birthday(int m, int d,int y); + void printDate(); + private: + int month; + int day; + int year; +}; + +#endif // BIRTHDAY_H + +//This is Birthday.cpp file +#include "Birthday.h" +#include +using namespace std; + +Birthday::Birthday(int m, int d, int y) +{ + month = m; + day = d; + year = y; +} + +void Birthday::printDate(){ + cout << month << "/" << day << "/" << year < +#include "Birthday.h" +using namespace std; + +class People +{ + public: + People(string x,Birthday bo); + void printInfo(); + private: + string name; + Birthday dataOfBirth; +}; + +#endif // PEOPLE_H + +//This is People.cpp file +#include "People.h" +#include "Birthday.h" +#include +using namespace std; + +People::People(String x,Birthday bo) +: name(x), dataOfBirth(bo) +{ +} + +void People::printInfo(){ + cout << name << "was born on"; + dataOfBirth.printDate(); +} +//This is main.cpp file +#include +#include "Birthday.h" +#include "People.h" +using namespace std; + +int main() +{ + Birthday birthObj(12,28,1986); + + People buckyRoberts("Bucky the King",birthObj); + buckyRoberts.printInfo(); + +} \ No newline at end of file diff --git a/C++/48_cppBeginners.cpp b/C++/48_cppBeginners.cpp new file mode 100644 index 0000000..fc7a5e5 --- /dev/null +++ b/C++/48_cppBeginners.cpp @@ -0,0 +1,25 @@ +//This is main.cpp file +#include +using namespace std; + +class StankFist{ + public: + StankFist()(stinkyVar=0;) + private: + int stinkyVar; + + friend void stinkysFriend(StankFist &sfo); +}; + +void stinkysFriend(StankFist &sfo) +{ + sfo.stinkyVar=99; + cout << sfo.stinkyVar < +#include "Hannah.h" +using namespace std; + +Hannah::Hannah(int num) +:h(num) +{ +} + +void Hannah::printCrap(){ + cout << "h=" << h <h=" << this->h < +#include "Sally.h" +using namespace std; + +Sally::Sally() +{ +} + +Sally::Sally(int a){ + num = a; +} +Sally Sally::operator+(Sally aso){ + Sally brandNew; + brandNew.num = num + aso.num; + return(brandNew); +} +//This is main.cpp file +#include +#include "Sally.h" +using namespace std; + +int main() +{ + Sally a(34); + Sally b(21); + Sally c; + c=a+b; + cout << c.num << endl; + +} diff --git a/C++/52_cppBeginners.cpp b/C++/52_cppBeginners.cpp new file mode 100644 index 0000000..607d974 --- /dev/null +++ b/C++/52_cppBeginners.cpp @@ -0,0 +1,59 @@ +//This is Mother.h file +#ifndef MOTHER_H +#define MOTHER_H + +class Mother +{ + public: + Mother(); + void sayName(); +}; + +#endif // MOTHER_H + +//This is Mother.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +Mother::Mother() +{ +} + +void Mother::sayName(){ + cout << "I am a RobnertsQ" << endl; +} + +//This is Daughter.h file +#ifndef DAUGHTER_H +#define DAUGHTER_H + +class Daughter: public Mother +{ + public: + Daughter(); +}; + +#endif // DAUGHTER_H + +//This is Daughter.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +Daughter::Daughter() +{ +} +//This is main.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +int main(){ + + Daughter tina; + tina.sayName(); +} diff --git a/C++/53_cppBeginners.cpp b/C++/53_cppBeginners.cpp new file mode 100644 index 0000000..73a0401 --- /dev/null +++ b/C++/53_cppBeginners.cpp @@ -0,0 +1,57 @@ +//This is Mother.h file +#ifndef MOTHER_H +#define MOTHER_H + +class Mother +{ + public: + int publicv; + protected: + int protectedv; + private: + int privatev; +}; + +#endif // MOTHER_H + +//This is Mother.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +//This is Daughter.h file +#ifndef DAUGHTER_H +#define DAUGHTER_H + +class Daughter: public Mother +{ + public: + void dosomething(); +}; + +#endif // DAUGHTER_H + +//This is Daughter.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +void Daughter::dosomething() +{ + publicv = 1; + protected = 2; +} +//This is main.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +int main(){ + + Daughter tina; + tina.dosomething(); +} + \ No newline at end of file diff --git a/C++/54_cppBeginners.cpp b/C++/54_cppBeginners.cpp new file mode 100644 index 0000000..e6d825f --- /dev/null +++ b/C++/54_cppBeginners.cpp @@ -0,0 +1,62 @@ +//This is Mother.h file +#ifndef MOTHER_H +#define MOTHER_H + +class Mother +{ + public: + Mother(); + ~Mother(); +}; + +#endif // MOTHER_H + +//This is Mother.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +Mother::Mother(){ + cout<< "I am the mother constructor!" << endl; +} + +Mother::~Mother(){ + cout<< "mother deconstructor!" << endl; +} +//This is Daughter.h file +#ifndef DAUGHTER_H +#define DAUGHTER_H + +class Daughter: public Mother +{ + public: + Daughter(); + ~Daughter(); +}; + +#endif // DAUGHTER_H + +//This is Daughter.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +void Daughter::dosomething() +{ + publicv = 1; + protected = 2; +} +//This is main.cpp file +#include +#include "Mother.h" +#include "Daughter.h" +using namespace std; + +int main(){ + + Daughter tina; + +} + \ No newline at end of file diff --git a/C++/55_cppBeginners.cpp b/C++/55_cppBeginners.cpp new file mode 100644 index 0000000..768f059 --- /dev/null +++ b/C++/55_cppBeginners.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +class Enemy{ + protected: + int attackPower; + public: + void setAttackPower(int a){ + attackPower=a; + } +}; +class Ninja: public Enemy{ + public: + void attack() + {cout << "i am a ninja, ninja chop! -" << attackPower <setAttackPower(29); + enemy2->setAttackPower(99); + n.attack(); + m.attack(); +} diff --git a/C++/56_cppBeginners.cpp b/C++/56_cppBeginners.cpp new file mode 100644 index 0000000..be5d70d --- /dev/null +++ b/C++/56_cppBeginners.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +class Enemy{ + public: + virtual void attack(){} + +}; +class Ninja: public Enemy{ + public: + void attack() + {cout << "ninja attack!" <attack(); + enemy2->attack(); + +} diff --git a/C++/57_cppBeginners.cpp b/C++/57_cppBeginners.cpp new file mode 100644 index 0000000..53a3423 --- /dev/null +++ b/C++/57_cppBeginners.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +class Enemy{ + public: + virtual void attack()=0; + +}; +class Ninja: public Enemy{ + public: + void attack() + {cout << "ninja attack!" <attack(); + enemy2->attack(); + +} diff --git a/C++/58_cppBeginners.cpp b/C++/58_cppBeginners.cpp new file mode 100644 index 0000000..56c30e8 --- /dev/null +++ b/C++/58_cppBeginners.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +template +bucky addCrap(bucky a, bucky b) +{ +return a+b; +} + +int main() +{ + int x=7, y=43,z; + z=addCrap(x,y); + cout << z < +using namespace std; + +template + +FIRST smaller(FIRST a, SECOND b) +{ +return (a +using namespace std; + +template +class Bucky{ + T first, second; + public: + Bucky(T a, T b) + { + first=a; + second=b; + } + T bigger(); +}; +template +T Bucky::bigger() +{ +return (first>second?first:second); +} + +int main() +{ + Bucky bo(258, 105); + cout << bo.bigger(); +} \ No newline at end of file diff --git a/C++/61_cppBeginners.cpp b/C++/61_cppBeginners.cpp new file mode 100644 index 0000000..c7e8b46 --- /dev/null +++ b/C++/61_cppBeginners.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +template +class Spunky{ + public: + Spunky(T x) + { + cout << x << " is not a character!" << endl; + } +}; +template <> +class Spunky{ + public: + Spunky(char x) + { + cout << x << " is needed character!" << endl; + } +}; +int main() +{ + Spunky obj1(7; + Spunky obj2(3.154); + Spunky obj3('q'); + +} \ No newline at end of file diff --git a/C++/62_cppBeginners.cpp b/C++/62_cppBeginners.cpp new file mode 100644 index 0000000..5e9c928 --- /dev/null +++ b/C++/62_cppBeginners.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main() +{ + try{ + int momsAge = 30; + int sonsAge = 34; + + if(sonsAge > momsAge) + { + throw 99; + } + }catch(int x); + cout << "son can not be older than mom ERROR NUMBER :" << x << endl; + } + +} diff --git a/C++/63_cppBeginners.cpp b/C++/63_cppBeginners.cpp new file mode 100644 index 0000000..179045a --- /dev/null +++ b/C++/63_cppBeginners.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main() +{ + try { + + int num1; + cout << "Enter first number :" << endl; + cin>> num1; + + int num2; + cout << "Enter second number :" << endl; + cin>> num2; + + if(num2 == 0){ + throw 0; + + } + + cout << num1/num2 << endl; + }catch(int x){ + cout << "you cant divide by 0" << x << endl; + } +} \ No newline at end of file