├── Find_Element_In_Array.cpp ├── Find_Max_In_Array.cpp ├── Find_Min_In_Array.cpp ├── First_Program.cpp ├── Function overloading.cpp ├── README.md ├── Reverse_An_Array.cpp ├── Template_Calculator.cpp ├── template.cpp ├── template_Array.cpp ├── template_Loop.cpp ├── template_Swap.cpp ├── template_functions.cpp ├── template_max.cpp ├── template_min.cpp └── template_with_diff_dtype_arg.cpp /Find_Element_In_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int input[100], count, i, num; 6 | 7 | cout << "Enter Number of Elements in Array\n"; 8 | cin >> count; 9 | 10 | cout << "Enter " << count << " numbers \n"; 11 | 12 | // Read array elements 13 | for(i = 0; i < count; i++){ 14 | cin >> input[i]; 15 | } 16 | 17 | cout << "Enter a number to serach in Array\n"; 18 | cin >> num; 19 | 20 | // search num in inputArray from index 0 to elementCount-1 21 | for(i = 0; i < count; i++){ 22 | if(input[i] == num){ 23 | cout << "Element found at index " << i; 24 | break; 25 | } 26 | } 27 | 28 | if(i == count){ 29 | cout << "Element Not Present in Input Array\n"; 30 | } 31 | 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Find_Max_In_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int inputArray[500], N, i, max; 6 | 7 | cout << "Enter Number of Elements in Array\n"; 8 | cin >> N; 9 | cout << "Enter " << N << " numbers\n"; 10 | 11 | /* Read array elements */ 12 | for(i = 0; i < N; i++){ 13 | cin >> inputArray[i]; 14 | } 15 | 16 | max = inputArray[0]; 17 | /* traverse array elements */ 18 | for(i = 1; i < N; i++){ 19 | if(inputArray[i] > max) 20 | max = inputArray[i]; 21 | } 22 | 23 | cout << "Maximum Element : " << max; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Find_Min_In_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int input[100], count, i, min; 6 | 7 | cout << "Enter Number of Elements in Array\n"; 8 | cin >> count; 9 | 10 | cout << "Enter " << count << " numbers \n"; 11 | 12 | // Read array elements 13 | for(i = 0; i < count; i++){ 14 | cin >> input[i]; 15 | } 16 | 17 | min = input[0]; 18 | // search num in inputArray from index 0 to elementCount-1 19 | for(i = 0; i < count; i++){ 20 | if(input[i] < min){ 21 | min = input[i]; 22 | } 23 | } 24 | 25 | cout << "Minimum Element\n" << min; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /First_Program.cpp: -------------------------------------------------------------------------------- 1 | // First Program using C++ 2 | // Date : 29 September 2021 3 | // Course : Object Oriented Programming 4 | 5 | #include // Add Preprocessor Directives 6 | using namespace std; 7 | 8 | int main() { 9 | cout << "Start Pogramming with C++"; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Function overloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | //Function Overloading 6 | 7 | int add(int x ,int y) 8 | { 9 | return x+y; 10 | } 11 | 12 | float add(float x ,float y) 13 | { 14 | return x+y; 15 | } 16 | 17 | double add (double x ,double y) 18 | { 19 | return x+y; 20 | } 21 | 22 | int main() 23 | { 24 | 25 | cout<<"Addition of 2 integer 2 and 4 is : "< 2 | using namespace std; 3 | 4 | int main(){ 5 | int input[500], output[500], count, i; 6 | 7 | cout << "Enter number of elements in array\n"; 8 | cin >> count; 9 | 10 | cout << "Enter " << count << " numbers \n"; 11 | 12 | for(i = 0; i < count; i++){ 13 | cin >> input[i]; 14 | } 15 | 16 | // Copy numbers from inputArray to outputArray in 17 | // reverse order 18 | for(i = 0; i < count; i++){ 19 | output[i] = input[count-i-1]; 20 | } 21 | // Print Reversed array 22 | cout << "Reversed Array\n"; 23 | for(i = 0; i < count; i++){ 24 | cout << output[i] << " "; 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Template_Calculator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class Calculator { 6 | private: 7 | T num1, num2; 8 | 9 | public: 10 | Calculator(T n1, T n2) { 11 | num1 = n1; 12 | num2 = n2; 13 | } 14 | 15 | void displayResult() { 16 | cout << "Numbers: " << num1 << " and " << num2 << "." << endl; 17 | cout << num1 << " + " << num2 << " = " << add() << endl; 18 | cout << num1 << " - " << num2 << " = " << subtract() << endl; 19 | cout << num1 << " * " << num2 << " = " << multiply() << endl; 20 | cout << num1 << " / " << num2 << " = " << divide() << endl; 21 | } 22 | 23 | T add() { return num1 + num2; } 24 | T subtract() { return num1 - num2; } 25 | T multiply() { return num1 * num2; } 26 | T divide() { return num1 / num2; } 27 | }; 28 | 29 | int main() { 30 | Calculator intCalc(2, 1); 31 | Calculator floatCalc(2.4, 1.2); 32 | 33 | cout << "Int results:" << endl; 34 | intCalc.displayResult(); 35 | 36 | cout << endl 37 | << "Float results:" << endl; 38 | floatCalc.displayResult(); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | //Templete in C++ 6 | 7 | template 8 | T add(T x,T y) 9 | { 10 | return x+y; 11 | } 12 | 13 | 14 | 15 | int main() 16 | { 17 | 18 | cout<<"Addition of 2 integer 2 and 4 is : "< 4 | 5 | using namespace std; 6 | 7 | 8 | template T sum(T a[], int length) 9 | { 10 | T result = a[0]; 11 | for (int i = 1; i < length; i ++) 12 | result += a[i]; 13 | 14 | return result; 15 | } 16 | 17 | int main(void) { 18 | int int_data[5]; 19 | float float_data[5]; 20 | int i = 0; 21 | 22 | // input 5 integers 23 | cout << "\nInput 5 integers :: \n" << endl; 24 | for (; i < 5; i++) 25 | cin >> int_data[i]; 26 | // print sum of 5 integers 27 | cout << "\nSum of above is :: " << sum(int_data, 5) << endl; 28 | 29 | // input 5 float numbers 30 | cout << "\nInput 5 floats :: \n" << endl; 31 | for (i = 0; i < 5; i ++) 32 | cin >> float_data[i]; 33 | // print sum of 5 float numbers 34 | cout << "\nSum of above is :: " << sum(float_data, 5) << endl; 35 | 36 | cin.get(); 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /template_Loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | class A 5 | { 6 | public: 7 | T arr[size]; 8 | void insert() 9 | { 10 | int i =1; 11 | for (int j=0;j t1; 29 | t1.insert(); 30 | t1.display(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /template_Swap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | void func_swap(T &arg1, T &arg2) 6 | { 7 | T temp; 8 | temp = arg1; 9 | arg1 = arg2; 10 | arg2 = temp; 11 | } 12 | 13 | int main() 14 | { 15 | int num1 = 10, num2 = 20; 16 | double d1 = 100.53, d2 = 435.54; 17 | char ch1 = 'A', ch2 = 'Z'; 18 | 19 | cout << "Original data\n"; 20 | cout << "num1 = " << num1 << "\tnum2 = " << num2< 2 | using namespace std; 3 | template 4 | P maxm(P x, P y){ 5 | return x>y ? x:y; 6 | } 7 | int main(){ 8 | cout<<"Max:"< 2 | using namespace std; 3 | template 4 | T mini(T x, T y){ 5 | return x < y ? x:y; 6 | 7 | } 8 | 9 | int main(){ 10 | cout<<"Mini:"<(7.7,5)< 2 | #include 3 | using namespace std; 4 | 5 | //Templete in C++ 6 | 7 | template 8 | U add(T x,U y) 9 | { 10 | return x+y; 11 | } 12 | 13 | 14 | 15 | int main() 16 | { 17 | 18 | cout<<"Addition of 2 integer and double 2 and 4.5 is : "<(2,4.5)<(5.5f,6.5)<(5.0256,6); 21 | 22 | return 0; 23 | } 24 | 25 | --------------------------------------------------------------------------------