├── Array.cpp ├── Break_continue_statement.cpp ├── Call_by_values.cpp ├── D0_while.cpp ├── Default_Arguments.cpp ├── Fibonacci_Series.cpp ├── Function_parameters.cpp ├── Greater_no.cpp ├── Inline_Static.cpp ├── Loop.cpp ├── OOPS ├── ArrayInClass.cpp ├── Class.cpp ├── Classrational_number_question1.exe ├── Friend_Function_Eg.cpp ├── Nesting_class.cpp ├── README.txt ├── fstream.cpp ├── read_double_array.exe └── staticMem_Methods.cpp ├── Pointers.cpp ├── README.md ├── Recursion_recursive.cpp ├── Shopkeeper_discount.cpp ├── StuctureUnionEnums.cpp ├── Triangle_type.cpp ├── Weather_its_square_or_rectangle.cpp └── While_loop.cpp /Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | // Array Example's 5 | int marks[5] = {89,67,57,89,99}; 6 | //cout<<"The marks are :"< 2 | using namespace std; 3 | int main(){ 4 | for (int i = 0; i <= 40 ; i++) 5 | { 6 | if ( i == 7){ 7 | break; 8 | } 9 | cout< 17 | using namespace std; 18 | int main(){ 19 | for ( int a = 0 ; a <= 40; a++) 20 | { 21 | if (a == 4){ 22 | continue; 23 | } 24 | cout< 2 | using namespace std; 3 | 4 | int sum(int a, int b){ 5 | int c = a + b; 6 | return c; 7 | } 8 | // This will not going to swap the number..!! 9 | // Beacuse the main function will give the copy of it's data, So the even after the swap function the main value didn't get changed..!! 10 | 11 | /*void swap(int a , int b) { 12 | int temp = a; 13 | a = b; 14 | b = temp; 15 | } 16 | */ 17 | // This swap function will work because this time we give the address of the integer x,y..!! 18 | void swappointer ( int* a, int* b){ 19 | int temp = *a; 20 | *a = *b; 21 | *b = temp; 22 | } 23 | 24 | int main(){ 25 | int x=4,y=5; 26 | cout<<"The value of a is "< 2 | using namespace std; 3 | 4 | int main() { 5 | int a = 1; 6 | do 7 | { 8 | cout< 2 | using namespace std; 3 | 4 | // Inline funcion helps to save compline time and extra work from computer..!! 5 | inline int product(int a , int b){ 6 | return a*b; 7 | } 8 | 9 | float moneyRecieved (int currentMoney , float factor = 1.04){ 10 | // Default aruguments has to be written at last like i gave argument after the currentmoney argument..!! 11 | return currentMoney * factor ; 12 | } 13 | 14 | int main(){ 15 | //int a,b; 16 | //cout<<"enter the value of a and b"<>a>>b; 18 | int money = 100000; 19 | cout<<"The money in you bank "< 2 | using namespace std; 3 | 4 | int fib(int n){ 5 | if (n<2){ 6 | return 1; 7 | } 8 | return fib(n-2) + fib(n-1); 9 | } 10 | int main(){ 11 | int a; 12 | cout<<"Enter you no. : "; 13 | cin>>a; 14 | cout<<"The fibonacci Number is "< 2 | using namespace std; 3 | 4 | // We need to write the function before calling it into the main function..!! 5 | /* 6 | int sum(int a, int b);{ 7 | int c = a + b; 8 | return c; 9 | } 10 | */ 11 | // But if we want to write it after the main function we can your the function prototype 12 | // Which give the assuration to the compiler that this funtion is here may be later down the code 13 | 14 | int sum(int a, int b); //---> Acceptable 15 | // we need to write the whole "int" within the brackets or we can only write (in , int)..!! 16 | // Now the compiler is detecting the sum fuction even i wrote it after the main function..!! 17 | void g(void); 18 | // if i will not give the Function prototype my compiler will raise a error the function void s not declared 19 | 20 | int main(){ 21 | int num1, num2; 22 | cout<<"Enter your first number : "<>num1; 24 | cout<<"Enter your second number : "<>num2; 26 | cout<<"Sum of the the number is "< 2 | using namespace std; 3 | int main(){ 4 | 5 | int a,b,c; 6 | cin>>a>>b>>c; 7 | 8 | if (a>b){ 9 | if (a>c){ 10 | cout<c){ 16 | cout< 2 | using namespace std; 3 | 4 | 5 | // Inline funcion helps to save compline time and extra work from computer..!! 6 | inline int product(int a , int b){ 7 | return a*b; 8 | } 9 | 10 | 11 | /* 12 | int product(int a , int b){ 13 | static int c = 0; // This function will only runs ones..!! 14 | c = c + 1;// Next time the function will be run, value of c will be retained.!! 15 | return a*b+c; 16 | } 17 | */ 18 | 19 | int main(){ 20 | int a,b; 21 | cout<<"enter the value of a and b"<>a>>b; 23 | // If i call a function so many times in a code, So it takes the memory and compile time 24 | // So to avoid the extras we use inline function replace the the data and helps to run fast ad saves time 25 | // But we can't use it in all code's we need to use it in small functions only otherwise it's not helpfull instead will // create issue and use your memry and the code size will be more. 26 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | //intialization, condition, updation 7 | 8 | for ( int i = 0; i <= 100 ; i++) 9 | { 10 | cout< 2 | using namespace std; 3 | 4 | class shop 5 | { 6 | private: 7 | int itemID[100]; 8 | int itemPrice[100]; 9 | int counter; 10 | public: 11 | void initcounter(void) { counter = 0 ;} 12 | void setPrice(void); 13 | void displayPrice(void); 14 | }; 15 | 16 | void shop :: setPrice(void) 17 | { 18 | cout<<"Enter Id of your item"<>itemID[counter]; 20 | cout<<"Set price of your item"<>itemPrice[counter]; 22 | counter++; 23 | } 24 | 25 | void shop :: displayPrice(void) 26 | { 27 | for (int i = 0; i < counter; i++) 28 | { 29 | cout<<"The price of itemId "< 2 | using namespace std; 3 | 4 | class employee 5 | { 6 | private: 7 | int A,B,C; 8 | public: 9 | int d,e; 10 | void setData(int a , int b , int c); 11 | void getData(){ 12 | cout< 3 | using namespace std; 4 | 5 | class Y; // Forward declaration 6 | 7 | class X 8 | { 9 | int data; 10 | public: 11 | void setvalue(int value) 12 | { 13 | data = value; 14 | } 15 | friend void add(X , Y); 16 | }; 17 | 18 | class Y 19 | { 20 | int num; 21 | public: 22 | void setvalue(int value) 23 | { 24 | num = value; 25 | } 26 | friend void add(X , Y); 27 | }; 28 | 29 | void add(X o1, Y o2){ 30 | cout<<" Sum of X and Y is"< 45 | using namespace std; 46 | 47 | class c2; 48 | class c1 49 | { 50 | int val1; 51 | friend void exchange(c1 &, c2 &); 52 | 53 | public: 54 | void setvalue(int a) 55 | { 56 | val1 = a; 57 | } 58 | 59 | void display(void) 60 | { 61 | cout << val1 << endl; 62 | } 63 | }; 64 | 65 | class c2 66 | { 67 | int val2; 68 | friend void exchange(c1 &, c2 &); 69 | 70 | public: 71 | void indata(int b) 72 | { 73 | val2 = b; 74 | } 75 | 76 | void display(void) 77 | { 78 | cout << val2 << endl; 79 | } 80 | }; 81 | 82 | void exchange(c1 &x, c2 &y) 83 | { 84 | int tmp; 85 | tmp = x.val1; 86 | x.val1 = y.val2; 87 | y.val2 = tmp; 88 | } 89 | 90 | int main() 91 | { 92 | c1 oc1; 93 | c2 oc2; 94 | 95 | oc1.setvalue(5); 96 | oc2.indata(6); 97 | exchange(oc1, oc2); 98 | 99 | cout << "The value of c1 after exchange is : "; 100 | oc1.display(); 101 | cout << " The value of c2 after exchange is : "; 102 | oc2.display(); 103 | 104 | return 0; 105 | } -------------------------------------------------------------------------------- /OOPS/Nesting_class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class binary 6 | { 7 | string s; 8 | 9 | public: 10 | void read(void); 11 | void chk_bin(void); 12 | void ones_compliment(void); 13 | void display(void); 14 | }; 15 | 16 | void binary :: read(void){ 17 | cout<<"Enter the number"<>s; 19 | }; 20 | 21 | void binary :: chk_bin(void){ 22 | for (int i = 0; i < s.length(); i++) 23 | { 24 | if (s.at(i)!='0' && s.at(i)!='1'){ 25 | cout<<"Incorrect binary Format "< 2 | -------------------------------------------------------------------------------- /OOPS/fstream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // out 8 | // Opening the file in write mode..!! 9 | 10 | int main() 11 | { 12 | fstream obj; 13 | obj.open("ABC.txt", ios::out); 14 | int a; 15 | if (!"ABC.txt") 16 | { 17 | cout << "The file is not found" << endl; 18 | } 19 | else 20 | { 21 | cout << "The file is found / Created" << endl; 22 | obj << "Hello my name is Ketan Thakur. And live in gurugram" << endl; 23 | obj.close(); 24 | } 25 | return 0; 26 | } 27 | 28 | // Append Mode 29 | // This will add the text at the end of the file. 30 | 31 | /* 32 | int main(){ 33 | fstream obj; 34 | obj.open("ABCD.txt",ios::app); // used append mode here 35 | if (!"ABCD.txt") 36 | { 37 | cout<<"The file is not found"< 2 | using namespace std; 3 | 4 | class Employee 5 | { 6 | private: 7 | int id; 8 | static int count; 9 | public: 10 | void setData(void) 11 | { 12 | cout<<"Enter the Id"<>id; 14 | count++; 15 | } 16 | void getData(void) 17 | { 18 | cout<<"The id of th employee is " << id << " and the is the employee number "< 2 | using namespace std; 3 | int main(){ 4 | // What is Pointer..?? 5 | // Data type which holds the address of other data type 6 | 7 | int a = 69; 8 | int* b = &a; 9 | // & ---> (Address of) operator 10 | cout<<"The Address of a : "<<&a< ( Address of) Dereference operator 14 | cout<<"The value of address a :"<<*b< 2 | using namespace std; 3 | 4 | int factorial(int n){ // Facorial of a number:---->>>// 6! = 6*5*4*3*2*1 = 720 5 | if (n <=1){ 6 | return 1; 7 | } 8 | return n * factorial(n - 1); 9 | // Dry Run 10 | // factorial(n) If user gave the value 4 11 | // factorial(4) = 4 * factorial(3)....But now acc to the condition the factorial n is <= 1; 12 | // factorial(3) = 4 * 3 * factorial(2) 13 | // factorial(2) = 4 * 3 * 2 * factorial(1) 14 | } 15 | int main() { 16 | int a; 17 | cout<<"Enter a Number : "<>a; 19 | cout<<"The Factorial of the given number is "< 2 | using namespace std; 3 | 4 | int main () { 5 | int quantity,price; 6 | cout<<"enter Quantity"<>quantity; 8 | price = quantity*100; 9 | if (price>1000) { 10 | cout<<"Total cost is "<< price-(price*.1)< 2 | using namespace std; 3 | 4 | // STUCTURE 5 | 6 | /* 7 | struct students // We can use typedef before struct for the shortcut 8 | { 9 | int sID; 10 | char Teacher; 11 | float mathmarks; 12 | }; // write the shortcut we want to use using typedef. 13 | 14 | int main(){ 15 | struct students ketan; // give variable a name. 16 | ketan.sID = 210213; // Variable name.values = value you want to assign 17 | ketan.Teacher = 'a'; // Variable name.values = value you want to assign 18 | ketan.mathmarks = 89; // Variable name.values = value you want to assign 19 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int a,b,c,sides; 7 | cout<<"Enter the a "<>a; 9 | cout<<" Enter the b "<>b; 11 | cout<<"Enter the c"<>c; 13 | 14 | if (a*a==b*b + c*c || b*b==c*c+a*a || c*c==a*a+b*b){ 15 | cout<<" Right angle Triangle."< 2 | using namespace std; 3 | 4 | int main() { 5 | int a,b; 6 | cin>>a; 7 | cin>>b; 8 | 9 | if (a==b) { 10 | cout<<"square"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a = 0; //Giving our variable a value first 6 | while (a <=30){ //condition 7 | cout<