├── .gitignore ├── .vscode └── settings.json ├── README.md ├── program1 └── program1.cpp ├── program10 └── program10.cpp ├── program11 └── program11.cpp ├── program12 └── program12.cpp ├── program13 └── program13.cpp ├── program14 └── program14.cpp ├── program15 └── program15.cpp ├── program16 └── program16.cpp ├── program17 └── program17.cpp ├── program18 └── program18.cpp ├── program19 └── program19.cpp ├── program2 └── program2.cpp ├── program20 └── program20.cpp ├── program21 └── program21.cpp ├── program22 └── program22.cpp ├── program23 └── program23.cpp ├── program24 └── program24.cpp ├── program25 └── program25.cpp ├── program26 └── program26.cpp ├── program27 └── program27.cpp ├── program28 └── program28.cpp ├── program29 └── program29.cpp ├── program3 └── comment.cpp ├── program30 └── program30.cpp ├── program31 └── program31.cpp ├── program32 └── program32.cpp ├── program33 └── program33.cpp ├── program34 └── program34.cpp ├── program35 └── program35.cpp ├── program36 └── program36.cpp ├── program38 └── program38.cpp ├── program39 └── program39.cpp ├── program4 └── program4.cpp ├── program40 └── program40.cpp ├── program41 └── program41.cpp ├── program42 └── program42.cpp ├── program43 └── program43.cpp ├── program44 └── program44.cpp ├── program45 ├── Student │ ├── Student.cpp │ └── Student.h ├── main.cpp └── tempCodeRunnerFile.cpp ├── program46 ├── Destructor │ ├── Destructor.cpp │ └── Destructor.h └── main.cpp ├── program47 ├── Student │ ├── Student.cpp │ └── Student.h └── main.cpp ├── program48 └── program48.cpp ├── program49 ├── Student │ ├── Student.cpp │ └── Student.h └── main.cpp ├── program5 └── program5.cpp ├── program50 └── main.cpp ├── program51 └── main.cpp ├── program52 └── main.cpp ├── program53 └── main.cpp ├── program54 └── main.cpp ├── program55 └── main.cpp ├── program56 └── main.cpp ├── program57 └── main.cpp ├── program6 └── program6.cpp ├── program7 └── program7.cpp ├── program8 └── program8.cpp ├── program9 └── program9.cpp └── summary.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "iostream": "cpp", 4 | "iomanip": "cpp", 5 | "ostream": "cpp", 6 | "array": "cpp", 7 | "*.tcc": "cpp", 8 | "cctype": "cpp", 9 | "clocale": "cpp", 10 | "cstdarg": "cpp", 11 | "cstdint": "cpp", 12 | "cstdio": "cpp", 13 | "cstdlib": "cpp", 14 | "ctime": "cpp", 15 | "cwchar": "cpp", 16 | "cwctype": "cpp", 17 | "exception": "cpp", 18 | "system_error": "cpp", 19 | "tuple": "cpp", 20 | "type_traits": "cpp", 21 | "initializer_list": "cpp", 22 | "iosfwd": "cpp", 23 | "istream": "cpp", 24 | "limits": "cpp", 25 | "new": "cpp", 26 | "sstream": "cpp", 27 | "stdexcept": "cpp", 28 | "streambuf": "cpp", 29 | "utility": "cpp", 30 | "typeinfo": "cpp", 31 | "cstring": "cpp" 32 | } 33 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C++ Tutorial series 2 | -------------------------------------------------------------------------------- /program1/program1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | cout << "Anisul Islam " << " M.Sc. in Software Development"; 6 | getch(); 7 | } -------------------------------------------------------------------------------- /program10/program10.cpp: -------------------------------------------------------------------------------- 1 | // Temperature converter 2 | // celsius = (fahrenheit-32) / 1.8 3 | // fahrenheit = 1.8 celsius + 32 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | double celsius, fahrenheit; 11 | cout << "Enter Celsius: "; 12 | cin >> celsius; 13 | 14 | fahrenheit = 1.8 * celsius + 32; 15 | 16 | cout << "Fahrenheit = " << fahrenheit; 17 | getch(); 18 | } -------------------------------------------------------------------------------- /program11/program11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int x = 3; 8 | int y = 2; 9 | 10 | x += y; 11 | cout << x << endl; 12 | 13 | x -= y; 14 | cout << x << endl; 15 | 16 | x *= y; 17 | cout << x << endl; 18 | 19 | x /= y; 20 | cout << x << endl; 21 | 22 | x %= y; 23 | cout << x << endl; 24 | 25 | getch(); 26 | } -------------------------------------------------------------------------------- /program12/program12.cpp: -------------------------------------------------------------------------------- 1 | // Unary Operator -> + (unary plus), - (unary minus), ++ , -- 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | 9 | int x = 5; 10 | cout << -x << endl; 11 | cout << x++ << endl; 12 | cout << ++x << endl; 13 | cout << x-- << endl; 14 | cout << --x << endl; 15 | 16 | getch(); 17 | } -------------------------------------------------------------------------------- /program13/program13.cpp: -------------------------------------------------------------------------------- 1 | // Bitwise Operator -> & (and), | (or), ^ (exor), >> (right shift) , << (left shift), ~ (not) 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a = 32; 9 | int b = 12; 10 | int c; 11 | 12 | c = a & b; 13 | cout << "a & b = " << c; 14 | 15 | c = a | b; 16 | cout << "a | b = " << c; 17 | 18 | c = a ^ b; 19 | cout << "a ^ b = " << c; 20 | 21 | // 2 times divided by 2 22 | c = a >> 2; 23 | cout << "a >> 2 = " << c; 24 | 25 | // 3 times divided by 2 26 | c = a >> 3; 27 | cout << "a >> 3 = " << c; 28 | 29 | 30 | c = a << 2; 31 | cout << "a << 2 = " << c; 32 | 33 | 34 | getch(); 35 | } -------------------------------------------------------------------------------- /program14/program14.cpp: -------------------------------------------------------------------------------- 1 | // special operator sizeof(), comma operator 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a; 9 | float f; 10 | double d; 11 | char ch; 12 | char name[20]; 13 | int num1, num2, sum; 14 | 15 | int c = sizeof(a); 16 | cout << c << endl; 17 | 18 | 19 | c = sizeof(name); 20 | cout << c << endl; 21 | 22 | sum = (num1=20, num2=10, sum = num1 + num2); 23 | cout << "sum is " << sum << endl; 24 | 25 | getch(); 26 | } -------------------------------------------------------------------------------- /program15/program15.cpp: -------------------------------------------------------------------------------- 1 | // Relational operator 2 | // statement 3 | // control statement - conditional (if, else if, else), loop (for, while, do while), jump (break, continue, return) 4 | // if, else if, else statement 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int number; 12 | 13 | if(number > 0) 14 | { 15 | cout << "Positive" << endl; 16 | } 17 | else if(number < 0) 18 | { 19 | cout << "Negative" << endl; 20 | } 21 | else 22 | { 23 | cout << "Zero" << endl; 24 | } 25 | 26 | getch(); 27 | } -------------------------------------------------------------------------------- /program16/program16.cpp: -------------------------------------------------------------------------------- 1 | // Letter grade program 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | int marks; 11 | cout << "Enter your marks = "; 12 | cin >> marks; 13 | 14 | if(marks>100) 15 | { 16 | cout << "Invalid Mark" << endl; 17 | } 18 | else if(marks< 0) 19 | { 20 | cout << "Invalid Mark" << endl; 21 | } 22 | else if(marks>=80) 23 | { 24 | cout << "A++" << endl; 25 | } 26 | else if(marks>=70) 27 | { 28 | cout << "A" << endl; 29 | } 30 | else if(marks>=60) 31 | { 32 | cout << "A-" << endl; 33 | } 34 | else if(marks>=50) 35 | { 36 | cout << "B" << endl; 37 | } 38 | else if(marks>=40) 39 | { 40 | cout << "C" << endl; 41 | } 42 | else if(marks>=33) 43 | { 44 | cout << "D" << endl; 45 | } 46 | else 47 | { 48 | cout << "Fail"; 49 | } 50 | 51 | getch(); 52 | } -------------------------------------------------------------------------------- /program17/program17.cpp: -------------------------------------------------------------------------------- 1 | // Letter grade program 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | int marks; 11 | cout << "Enter your marks = "; 12 | cin >> marks; 13 | 14 | if(marks>100 && marks< 0) 15 | { 16 | cout << "Invalid Mark" << endl; 17 | } 18 | else if(marks>=80) 19 | { 20 | cout << "A++" << endl; 21 | } 22 | else if(marks>=70) 23 | { 24 | cout << "A" << endl; 25 | } 26 | else if(marks>=60) 27 | { 28 | cout << "A-" << endl; 29 | } 30 | else if(marks>=50) 31 | { 32 | cout << "B" << endl; 33 | } 34 | else if(marks>=40) 35 | { 36 | cout << "C" << endl; 37 | } 38 | else if(marks>=33) 39 | { 40 | cout << "D" << endl; 41 | } 42 | else 43 | { 44 | cout << "Fail"; 45 | } 46 | 47 | getch(); 48 | } -------------------------------------------------------------------------------- /program18/program18.cpp: -------------------------------------------------------------------------------- 1 | // Vowel / Consonant 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | char ch; 11 | cout << "Enter a letter = "; 12 | cin >> ch; 13 | 14 | // convert any uppercase letter to lowercase letter 15 | ch = tolower(ch); 16 | 17 | if(ch =='a' || ch =='e' || ch=='i' || ch=='o' || ch=='u') 18 | { 19 | cout << "Vowel" << endl; 20 | } 21 | 22 | else 23 | { 24 | cout << "Consonant" << endl; 25 | } 26 | 27 | getch(); 28 | } -------------------------------------------------------------------------------- /program19/program19.cpp: -------------------------------------------------------------------------------- 1 | // large / small number among 3 numbers 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | 11 | int num1, num2, num3, large; 12 | cout << "Enter 3 numbers: "; 13 | cin >> num1 >> num2 >> num3; 14 | 15 | if(num1> num2 && num1 > num3) 16 | { 17 | large = num1; 18 | } 19 | else if(num2> num1 && num2 > num3) 20 | { 21 | large = num2; 22 | } 23 | else 24 | { 25 | large = num3; 26 | } 27 | 28 | cout << "Large Number is : " << large << endl; 29 | 30 | getch(); 31 | } -------------------------------------------------------------------------------- /program2/program2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | cout << "Anisul Islam.\nM.Sc. in Software Development\n"; 7 | 8 | 9 | cout << "I am from Bangladesh. My Phone number is \t 01444" << endl; 10 | cout << "I am currently living in Finaland"; 11 | getch(); 12 | } -------------------------------------------------------------------------------- /program20/program20.cpp: -------------------------------------------------------------------------------- 1 | // Leap Year 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | 11 | int year; 12 | 13 | if ((year%4 == 0 && year%100 != 0) || year % 400 == 0) 14 | { 15 | cout << "Leap Year"; 16 | } 17 | else{ 18 | cout << "Not Leap Year"; 19 | } 20 | 21 | getch(); 22 | } -------------------------------------------------------------------------------- /program21/program21.cpp: -------------------------------------------------------------------------------- 1 | // Ternary Operator / conditional operator 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | 11 | 12 | int num1, num2; 13 | 14 | cout << "Enter two numbers: "; 15 | cin >> num1 >> num2; 16 | 17 | int large = num1>num2 ? num1 : num2; 18 | 19 | cout << "Large Number is : " << large << endl; 20 | 21 | getch(); 22 | } -------------------------------------------------------------------------------- /program22/program22.cpp: -------------------------------------------------------------------------------- 1 | // switch , case, break, default 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int digit; 10 | 11 | cout << "Enter a digit : "; 12 | cin >> digit; 13 | 14 | switch(digit) 15 | { 16 | case 0: 17 | cout << "Zero"; 18 | break; 19 | case 1: 20 | cout << "One"; 21 | break; 22 | case 2: 23 | cout << "Two"; 24 | break; 25 | case 3: 26 | cout << "Three"; 27 | break; 28 | case 4: 29 | cout << "Four"; 30 | break; 31 | case 5: 32 | cout << "Five"; 33 | break; 34 | case 6: 35 | cout << "Six"; 36 | break; 37 | case 7: 38 | cout << "Seven"; 39 | break; 40 | case 8: 41 | cout << "Eight"; 42 | break; 43 | case 9: 44 | cout << "Nine"; 45 | break; 46 | default: 47 | cout << "Not a digit"; 48 | 49 | } 50 | 51 | getch(); 52 | } -------------------------------------------------------------------------------- /program23/program23.cpp: -------------------------------------------------------------------------------- 1 | 2 | //for loop 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | 11 | int x; 12 | 13 | for(x=1; x<=10; x++) 14 | { 15 | cout << x << endl; 16 | } 17 | 18 | getch(); 19 | } -------------------------------------------------------------------------------- /program24/program24.cpp: -------------------------------------------------------------------------------- 1 | 2 | //while loop 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | 11 | int x=1; 12 | 13 | while(x<=10) 14 | { 15 | cout << x << endl; 16 | x++; 17 | } 18 | 19 | getch(); 20 | } -------------------------------------------------------------------------------- /program25/program25.cpp: -------------------------------------------------------------------------------- 1 | 2 | // do while loop 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | 11 | int x=1; 12 | 13 | 14 | do { 15 | cout << x << endl; 16 | x++; 17 | } while(x<=10); 18 | 19 | getch(); 20 | } -------------------------------------------------------------------------------- /program26/program26.cpp: -------------------------------------------------------------------------------- 1 | 2 | // break and continue keyword 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int x; 11 | for(x=1; x<=100; x++) 12 | { 13 | if(x==10) 14 | continue; 15 | 16 | cout << x < 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int num, i; 8 | 9 | cout << "Enter a number : "; 10 | cin >> num; 11 | 12 | for (i=1; i<=10; i++) 13 | { 14 | cout << num << " X " << i << " = " << num * i << endl; 15 | } 16 | 17 | 18 | getch(); 19 | } -------------------------------------------------------------------------------- /program28/program28.cpp: -------------------------------------------------------------------------------- 1 | // series 2 | // 1 + 2 + 3 + ... + n 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | 10 | int i, n, sum=0; 11 | 12 | cout << "Enter the last number : "; 13 | cin >> n; 14 | 15 | for (i=1; i<=n; i++) 16 | { 17 | sum = sum + i; 18 | } 19 | 20 | cout << "sum is : " << sum << endl; 21 | 22 | getch(); 23 | } -------------------------------------------------------------------------------- /program29/program29.cpp: -------------------------------------------------------------------------------- 1 | 2 | // pattern program 3 | /* 4 | n=3 5 | * 6 | ** 7 | *** 8 | */ 9 | 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | int i,j,n; 17 | cout << "Enter n = "; 18 | cin >> n; 19 | 20 | for(i=1; i<=n; i++) 21 | { 22 | for(j=1 ; j<=i ; j++) 23 | { 24 | cout << "*" ; 25 | } 26 | cout << endl; 27 | } 28 | 29 | getch(); 30 | } -------------------------------------------------------------------------------- /program3/comment.cpp: -------------------------------------------------------------------------------- 1 | // A simple program to show the use of comment 2 | #include 3 | using namespace std; 4 | /* 5 | This is 6 | a 7 | multiple line 8 | comment 9 | */ 10 | int main() 11 | { 12 | // printing my name 13 | cout << "Anisul Islam" << endl; 14 | // printing my phone 15 | cout << "01710444700" << endl; 16 | } -------------------------------------------------------------------------------- /program30/program30.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | // declaring an array 9 | int marks[5]; 10 | int x; 11 | 12 | //initializing an array 13 | marks[0] = 35; 14 | marks[1] = 45; 15 | marks[2] = 33; 16 | marks[3] = 83; 17 | marks[4] = 93; 18 | 19 | // printing an array 20 | for(x=0; x<5; x++) 21 | { 22 | cout << marks[x] << endl; 23 | } 24 | 25 | getch(); 26 | } -------------------------------------------------------------------------------- /program31/program31.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int marks[5]; 9 | int x; 10 | 11 | for(x=0; x<5; x++) 12 | { 13 | cout << "Marks for student " << x+1 << " = "; 14 | cin >> marks[x]; 15 | } 16 | 17 | // printing an array 18 | for(x=0; x<5; x++) 19 | { 20 | cout << marks[x] << endl; 21 | } 22 | 23 | getch(); 24 | } -------------------------------------------------------------------------------- /program32/program32.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int n,x, sum=0; 9 | 10 | cout << "How many students : "; 11 | cin >> n; 12 | 13 | int students[n]; 14 | 15 | for(x=0 ; x< n; x++) 16 | { 17 | cout << "student " << x+1 << " = "; 18 | cin >> students[x]; 19 | sum = sum + students[x]; 20 | } 21 | 22 | cout << "Total Marks: " << sum << endl; 23 | cout << "Average Marks: " << (float)sum / n << endl; 24 | 25 | 26 | int max = students[0]; 27 | int min = students[0]; 28 | 29 | for(x=1; x students[x]) 36 | { 37 | min = students[x]; 38 | } 39 | } 40 | 41 | cout << "Maximum Marks: " << max << endl; 42 | cout << "Minimum Marks: " << min << endl; 43 | 44 | getch(); 45 | } -------------------------------------------------------------------------------- /program33/program33.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int row, col, A[2][2], B[2][2]; 8 | 9 | cout << "Enter the element for Matrix" << endl; 10 | 11 | for(row=0; row<2; row++) 12 | { 13 | for(col=0; col<2; col++) 14 | { 15 | cout << "A[" << row << "][" << col << "] = "; 16 | cin >> A[row][col]; 17 | } 18 | } 19 | 20 | for(row=0; row<2; row++) 21 | { 22 | for(col=0; col<2; col++) 23 | { 24 | cout << A[row][col] << " "; 25 | } 26 | cout << endl; 27 | } 28 | 29 | 30 | 31 | getch(); 32 | } -------------------------------------------------------------------------------- /program34/program34.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int num1 = 20; 8 | int num2 = 30; 9 | 10 | int *p1, *p2; 11 | 12 | p1 = &num1; 13 | p2 = &num2; 14 | 15 | int sum = *p1 + *p2; 16 | 17 | cout << sum << endl; 18 | 19 | getch(); 20 | } -------------------------------------------------------------------------------- /program35/program35.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // function without parameter 6 | void add1() 7 | { 8 | cout << "Nothing to add" << endl ; 9 | } 10 | 11 | 12 | // function with parameter having default values 13 | void add2(int x=10, int y=10) 14 | { 15 | int sum = x + y; 16 | cout << "Sum : " << sum << endl; 17 | } 18 | 19 | // function returning a value 20 | int square (int x) 21 | { 22 | return x*x; 23 | } 24 | 25 | int main() 26 | { 27 | 28 | add1(); 29 | add2(10,20); 30 | 31 | cout << "Square of 4 = " << square(4) << endl; 32 | 33 | getch(); 34 | } -------------------------------------------------------------------------------- /program36/program36.cpp: -------------------------------------------------------------------------------- 1 | // Random Number 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | 10 | int x; 11 | 12 | for(x=1; x<=5; x++) 13 | { 14 | int randomNumber = rand() % 5 + 1; 15 | cout << "Random Number is : " << randomNumber << endl; 16 | } 17 | 18 | getch(); 19 | } -------------------------------------------------------------------------------- /program38/program38.cpp: -------------------------------------------------------------------------------- 1 | // function overloading 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | void add(int x, int y) 9 | { 10 | int sum = x + y; 11 | cout << "Sum : " << sum << endl; 12 | } 13 | 14 | 15 | void add(int x, int y, int z) 16 | { 17 | int sum = x + y + z; 18 | cout << "Sum : " << sum << endl; 19 | } 20 | 21 | int main() 22 | { 23 | 24 | add(10, 20); 25 | add(10, 20, 30); 26 | 27 | getch(); 28 | } -------------------------------------------------------------------------------- /program39/program39.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | void displayArray(int num[], int size) 7 | { 8 | int x; 9 | for(x=0; x 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int id, age; 8 | float cgpa = 3.92; 9 | 10 | id = 1302020017; 11 | age = 31; 12 | 13 | cout << "Student Id : " << id << endl; 14 | cout << "Student age: " << age << endl; 15 | cout << "Student cgpa: " << cgpa << endl; 16 | 17 | getch(); 18 | 19 | } -------------------------------------------------------------------------------- /program40/program40.cpp: -------------------------------------------------------------------------------- 1 | // Recursion 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int factorial(int n) 9 | { 10 | 11 | if(n==1) 12 | return n; 13 | else 14 | return n * factorial(n-1); 15 | } 16 | 17 | int main() 18 | { 19 | 20 | cout << "Factorial of 5 = " << factorial (5) << endl; 21 | 22 | getch(); 23 | } -------------------------------------------------------------------------------- /program41/program41.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Student 6 | { 7 | 8 | public: 9 | //variables 10 | int id; 11 | double gpa; 12 | //functions 13 | 14 | }; 15 | 16 | int main() 17 | { 18 | 19 | cout << "ID" << " " << "GPA" << endl; 20 | cout << "-----------"<< endl; 21 | 22 | 23 | Student s1,s2; 24 | s1.id = 101; 25 | s1.gpa = 3.92; 26 | 27 | cout << s1.id << " " << s1.gpa << endl; 28 | 29 | 30 | s2.id = 102; 31 | s2.gpa = 3.44; 32 | 33 | cout << s2.id << " " << s2.gpa << endl; 34 | 35 | getch(); 36 | } -------------------------------------------------------------------------------- /program42/program42.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Student 6 | { 7 | 8 | public: 9 | //variables 10 | int id; 11 | double gpa; 12 | //functions 13 | void display() 14 | { 15 | cout << id << " " << gpa << endl; 16 | } 17 | 18 | }; 19 | 20 | int main() 21 | { 22 | 23 | cout << "ID" << " " << "GPA" << endl; 24 | cout << "-----------"<< endl; 25 | 26 | 27 | Student s1,s2; 28 | s1.id = 101; 29 | s1.gpa = 3.92; 30 | s1.display(); 31 | 32 | 33 | 34 | 35 | s2.id = 102; 36 | s2.gpa = 3.44; 37 | s2.display(); 38 | 39 | getch(); 40 | } -------------------------------------------------------------------------------- /program43/program43.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Student 6 | { 7 | 8 | public: 9 | //variables 10 | int id; 11 | double gpa; 12 | //functions 13 | void display() 14 | { 15 | cout << id << " " << gpa << endl; 16 | } 17 | 18 | void setValue(int x, double y) 19 | { 20 | id = x; 21 | gpa = y; 22 | } 23 | 24 | }; 25 | 26 | int main() 27 | { 28 | 29 | cout << "ID" << " " << "GPA" << endl; 30 | cout << "-----------"<< endl; 31 | 32 | 33 | Student s1,s2; 34 | s1.setValue(101, 3.92); 35 | s1.display(); 36 | 37 | s2.setValue(102, 3.44); 38 | s2.display(); 39 | 40 | getch(); 41 | } -------------------------------------------------------------------------------- /program44/program44.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Student 6 | { 7 | 8 | public: 9 | //variables 10 | int id; 11 | double gpa; 12 | 13 | //functions 14 | void display() 15 | { 16 | cout << id << " " << gpa << endl; 17 | } 18 | 19 | // default constructor 20 | Student() 21 | { 22 | cout << "This is a default constructor" << endl; 23 | } 24 | 25 | // parametrized constructor 26 | Student(int x, double y) 27 | { 28 | id = x; 29 | gpa = y; 30 | } 31 | 32 | }; 33 | 34 | int main() 35 | { 36 | 37 | Student(); 38 | 39 | cout << "ID" << " " << "GPA" << endl; 40 | cout << "-----------"<< endl; 41 | 42 | Student s1(101,3.92); 43 | s1.display(); 44 | 45 | Student s2(102,3.44); 46 | s2.display(); 47 | 48 | getch(); 49 | } -------------------------------------------------------------------------------- /program45/Student/Student.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Student.h" 3 | #include 4 | using namespace std; 5 | 6 | 7 | Student::Student() 8 | { 9 | cout << "This is a default constructor" << endl; 10 | } 11 | Student::Student(int x, double y) 12 | { 13 | id = x; 14 | gpa = y; 15 | } 16 | 17 | //functions 18 | void Student:: display() 19 | { 20 | cout << id << " " << gpa << endl; 21 | } -------------------------------------------------------------------------------- /program45/Student/Student.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Student 6 | { 7 | 8 | public: 9 | //variables 10 | int id; 11 | double gpa; 12 | 13 | //functions 14 | void display(); 15 | 16 | // default constructor 17 | Student(); 18 | 19 | // parametrized constructor 20 | Student(int x, double y); 21 | 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /program45/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Student/Student.h" 3 | #include 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | Student(); 10 | 11 | cout << "ID" << " " << "GPA" << endl; 12 | cout << "-----------"<< endl; 13 | 14 | Student s1(101,3.92); 15 | s1.display(); 16 | 17 | Student s2(102,3.44); 18 | s2.display(); 19 | 20 | getch(); 21 | } -------------------------------------------------------------------------------- /program45/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | #include "Student/Student.h" -------------------------------------------------------------------------------- /program46/Destructor/Destructor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Destructor.h" 3 | #include 4 | using namespace std; 5 | 6 | 7 | //functions 8 | Destructor:: Destructor() 9 | { 10 | cout << "I am constructor " << endl; 11 | } 12 | 13 | Destructor:: ~Destructor() 14 | { 15 | cout << "I am destructor " << endl; 16 | } 17 | 18 | void Destructor:: display() 19 | { 20 | cout << "I am display function " << endl; 21 | } -------------------------------------------------------------------------------- /program46/Destructor/Destructor.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Destructor 6 | { 7 | public: 8 | //functions 9 | Destructor(); 10 | ~Destructor(); 11 | void display(); 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /program46/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Destructor/Destructor.h" 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | 10 | Destructor obj; 11 | obj.display(); 12 | 13 | getch(); 14 | } -------------------------------------------------------------------------------- /program47/Student/Student.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Student.h" 3 | using namespace std; 4 | 5 | 6 | void Student:: display() 7 | { 8 | 9 | cout << "I am display function"; 10 | 11 | } -------------------------------------------------------------------------------- /program47/Student/Student.h: -------------------------------------------------------------------------------- 1 | class Student 2 | { 3 | 4 | public: 5 | void display(); 6 | 7 | }; -------------------------------------------------------------------------------- /program47/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Student/Student.h" 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | Student s1; 9 | Student *p = &s1; 10 | 11 | p -> display(); 12 | 13 | getch(); 14 | } -------------------------------------------------------------------------------- /program48/program48.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | char name[30]; 10 | char copyName[30]; 11 | 12 | cout << "Enter your name please : "; 13 | gets(name); 14 | cout << "Hello " << name << endl; 15 | 16 | int len = strlen(name); 17 | cout << "Length of string : " << len << endl; 18 | 19 | strcpy(copyName, name); 20 | cout << "CopyName: " << copyName << endl; 21 | 22 | 23 | char msg1[] = "Hello"; 24 | char msg2[] = " Everyone"; 25 | strcat(msg1, msg2); 26 | cout << "Message1: " << msg1 << endl; 27 | 28 | int value = strcmp("Anis", "anis"); 29 | if(value==0){ 30 | cout << "Strings are equal" << endl; 31 | }else{ 32 | cout << "Strings are not equal" << endl; 33 | } 34 | 35 | getch(); 36 | } -------------------------------------------------------------------------------- /program49/Student/Student.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Student.h" 3 | using namespace std; 4 | 5 | void Student :: setName (string name) 6 | { 7 | this -> name = name; 8 | } 9 | 10 | string Student :: getName () 11 | { 12 | return name; 13 | } 14 | void Student :: setAge (int age) 15 | { 16 | this -> age = age; 17 | } 18 | 19 | int Student :: getAge () 20 | { 21 | return age; 22 | } -------------------------------------------------------------------------------- /program49/Student/Student.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Student 7 | { 8 | 9 | private: 10 | string name; 11 | int age; 12 | 13 | public: 14 | void setName(string name); 15 | string getName(); 16 | void setAge(int age); 17 | int getAge(); 18 | }; -------------------------------------------------------------------------------- /program49/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Student/Student.h" 4 | using namespace std; 5 | 6 | 7 | int main() 8 | { 9 | Student s1; 10 | s1.setName("Anisul Islam"); 11 | cout << s1.getName() << endl; 12 | 13 | 14 | s1.setAge(29); 15 | cout << s1.getAge() << endl; 16 | 17 | getch(); 18 | } -------------------------------------------------------------------------------- /program5/program5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | char name[13] = "Anisul Islam"; 8 | 9 | cout << "My name is : " << name < 3 | #include 4 | using namespace std; 5 | 6 | class Person 7 | { 8 | public: 9 | string name; 10 | int age; 11 | 12 | void display1() 13 | { 14 | cout << "Name: " << name << endl; 15 | cout << "Age: " << age << endl; 16 | } 17 | }; 18 | 19 | class Student : public Person 20 | { 21 | // name, age, display() 22 | public: 23 | int id; 24 | 25 | void display2() 26 | { 27 | cout << "ID: " << id << endl; 28 | display1(); 29 | } 30 | 31 | 32 | }; 33 | 34 | int main() 35 | { 36 | 37 | Student s1; 38 | s1.id = 101; 39 | s1.name = "Anisul Islam"; 40 | s1.age = 29; 41 | s1.display2(); 42 | 43 | getch(); 44 | } -------------------------------------------------------------------------------- /program51/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | class Person 7 | { 8 | 9 | public: 10 | void display() 11 | { 12 | cout << "I am a person" << endl; 13 | } 14 | 15 | }; 16 | class Student : public Person 17 | { 18 | 19 | public: 20 | void display() 21 | { 22 | cout << "I am a Student" << endl; 23 | } 24 | 25 | }; 26 | class Teacher : public Person 27 | { 28 | 29 | public: 30 | void display() 31 | { 32 | cout << "I am a Teacher" << endl; 33 | } 34 | 35 | }; 36 | 37 | 38 | int main() 39 | { 40 | Person p; 41 | p.display(); 42 | 43 | Student s; 44 | s.display(); 45 | 46 | Teacher t; 47 | t.display(); 48 | 49 | 50 | } -------------------------------------------------------------------------------- /program52/main.cpp: -------------------------------------------------------------------------------- 1 | // polymorphism example 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | class Person 8 | { 9 | 10 | public: 11 | virtual void display() 12 | { 13 | cout << "I am a person" << endl; 14 | } 15 | 16 | }; 17 | class Student : public Person 18 | { 19 | 20 | public: 21 | void display() 22 | { 23 | cout << "I am a Student" << endl; 24 | } 25 | 26 | }; 27 | class Teacher : public Person 28 | { 29 | 30 | public: 31 | void display() 32 | { 33 | cout << "I am a Teacher" << endl; 34 | } 35 | 36 | }; 37 | 38 | 39 | int main() 40 | { 41 | Person *p; 42 | Student s; 43 | Teacher t; 44 | 45 | p = &s; 46 | p -> display(); 47 | 48 | p = &t; 49 | p -> display(); 50 | 51 | 52 | } -------------------------------------------------------------------------------- /program53/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Shape 6 | { 7 | public: 8 | double dim1, dim2; 9 | 10 | Shape(double dim1, double dim2) 11 | { 12 | this -> dim1 = dim1; 13 | this -> dim2 = dim2; 14 | } 15 | 16 | virtual double area() 17 | { 18 | return 0; 19 | } 20 | }; 21 | 22 | class Triangle: public Shape 23 | { 24 | public: 25 | Triangle(double dim1, double dim2) 26 | : Shape(dim1, dim2) 27 | { 28 | } 29 | 30 | double area() 31 | { 32 | return 0.5 * dim1 * dim2; 33 | } 34 | }; 35 | 36 | class Rectangle: public Shape 37 | { 38 | public: 39 | Rectangle(double dim1, double dim2) 40 | : Shape(dim1, dim2) 41 | { 42 | } 43 | 44 | double area() 45 | { 46 | return dim1 * dim2; 47 | } 48 | }; 49 | 50 | int main() 51 | { 52 | Shape *s; 53 | Triangle t(10,20); 54 | Rectangle r(10,20); 55 | 56 | s = &t; 57 | cout << "Triangle Area: " << s->area() << endl; 58 | 59 | s = &r; 60 | cout << "Rectangle Area: " << s->area() << endl; 61 | 62 | 63 | getch(); 64 | } -------------------------------------------------------------------------------- /program54/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Shape 6 | { 7 | public: 8 | double dim1, dim2; 9 | 10 | Shape(double dim1, double dim2) 11 | { 12 | this -> dim1 = dim1; 13 | this -> dim2 = dim2; 14 | } 15 | 16 | // pure virtual function, so the class Shape will be called abstract class 17 | // Abstract class object is not possible but pointer can be used 18 | // if any class inherit an abstract class then abstract method must be used or the class itself has to be abstract 19 | virtual double area() = 0; 20 | }; 21 | 22 | class Triangle: public Shape 23 | { 24 | public: 25 | Triangle(double dim1, double dim2) 26 | : Shape(dim1, dim2) 27 | { 28 | } 29 | 30 | double area() 31 | { 32 | return 0.5 * dim1 * dim2; 33 | } 34 | }; 35 | 36 | class Rectangle: public Shape 37 | { 38 | public: 39 | Rectangle(double dim1, double dim2) 40 | : Shape(dim1, dim2) 41 | { 42 | } 43 | 44 | double area() 45 | { 46 | return dim1 * dim2; 47 | } 48 | }; 49 | 50 | int main() 51 | { 52 | Shape *s; 53 | Triangle t(10,20); 54 | Rectangle r(10,20); 55 | 56 | s = &t; 57 | cout << "Triangle Area: " << s->area() << endl; 58 | 59 | s = &r; 60 | cout << "Rectangle Area: " << s->area() << endl; 61 | 62 | 63 | getch(); 64 | } -------------------------------------------------------------------------------- /program55/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class A 6 | { 7 | private: 8 | int id = 101; 9 | string name = "Anisul Islam"; 10 | 11 | public: 12 | friend class B; 13 | }; 14 | 15 | class B 16 | { 17 | public: 18 | void display(A obj) 19 | { 20 | cout << obj.id << " " << obj.name << endl; 21 | } 22 | }; 23 | 24 | int main() 25 | { 26 | A ob1; 27 | B ob2; 28 | ob2.display(ob1); 29 | 30 | getch(); 31 | } -------------------------------------------------------------------------------- /program56/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | template 6 | myTemplate add (myTemplate a, myTemplate2 b) 7 | { 8 | return a+b; 9 | } 10 | 11 | int main() 12 | { 13 | cout << add(10,20) << endl; 14 | cout << add(10.5,20) << endl; 15 | 16 | getch(); 17 | } -------------------------------------------------------------------------------- /program57/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | 9 | while(1) 10 | { 11 | try{ 12 | int num1, num2; 13 | cout << "Enter first number : "; 14 | cin >> num1; 15 | 16 | cout << "Enter Second number : "; 17 | cin >> num2; 18 | 19 | if(num2==0) 20 | { 21 | throw -1; 22 | } 23 | 24 | double result = (double) num1 / num2; 25 | cout << "Result is : " << result << endl; 26 | } 27 | catch(...) 28 | { 29 | cout << "Divide by 0 is not possible" << endl; 30 | cout << "Please try again" << endl; 31 | } 32 | } 33 | 34 | 35 | } -------------------------------------------------------------------------------- /program6/program6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main () 6 | { 7 | 8 | char name[20]; 9 | float gpa; 10 | 11 | // taking user input 12 | cout << "Enter your name : " << endl; 13 | cin >> name; 14 | cout << "Enter your gpa : " << endl; 15 | cin >> gpa; 16 | 17 | //printing 18 | cout << "---------------------------" << endl; 19 | cout << "Name : " << name << endl; 20 | cout << "GPA : " << gpa << endl; 21 | cout << "---------------------------" << endl; 22 | getch(); 23 | } -------------------------------------------------------------------------------- /program7/program7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int num1, num2, result; 8 | cout << "Enter num1 : "; 9 | cin >> num1; 10 | 11 | cout << "Enter num2 : "; 12 | cin >> num2; 13 | 14 | result = num1 + num2; 15 | cout << "sum is : " << result << endl; 16 | 17 | result = num1 - num2; 18 | cout << "sub is : " << result << endl; 19 | 20 | result = num1 * num2; 21 | cout << "Mul is : " << result << endl; 22 | 23 | result = num1 / num2; 24 | cout << "div is : " << result < 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // showpoint 8 | // noshowpoint 9 | // setprecision 10 | 11 | int main() 12 | { 13 | float num1, num2, result; 14 | cout << "Enter num1 : "; 15 | cin >> num1; 16 | 17 | cout << "Enter num2 : "; 18 | cin >> num2; 19 | 20 | cout << showpoint; 21 | 22 | result = num1 + num2; 23 | cout << setw(10) << "sum is : " << result << endl; 24 | 25 | result = num1 - num2; 26 | cout << setw(10) << "sub is : " << result << endl; 27 | 28 | cout << noshowpoint; 29 | result = num1 * num2; 30 | cout << setw(10) << "Mul is : " << result << endl; 31 | 32 | cout << fixed; 33 | cout << setprecision(5); 34 | result = num1 / num2; 35 | cout << setw(10) << "div is : " << result < 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | float base, height, area; 9 | 10 | cout << "Enter Base = "; 11 | cin >> base; 12 | 13 | cout << "Enter Height = "; 14 | cin >> height; 15 | 16 | // area = (float)1/2 * base * height; 17 | // area = 1.0/2 * base * height; 18 | area = 0.5 * base * height; 19 | 20 | 21 | cout << "Area of triangle : " << area; 22 | 23 | getch(); 24 | } -------------------------------------------------------------------------------- /summary.txt: -------------------------------------------------------------------------------- 1 | 1. Introduction to c++ 2 | - what is C++ ? 3 | - usage of C++ 4 | - History of C++ 5 | - Features of C++ 6 | 7 | 8 | 2. Translator Program 9 | 3. Software Installation 10 | 4. First C++ Program and its various parts 11 | 5. Escape Sequences 12 | 6. Types of comment 13 | 7. keyword, variable and data-Types 14 | 8. String variables 15 | 9. How to get user Input 16 | 10. how to run a class from a different file 17 | - create the header file and include in main.cpp 18 | - header file have only prototype t 19 | - body will include the header file and use the functions 20 | - run - g++ main.cpp .\Message\Message.cpp 21 | - then .\a.exe --------------------------------------------------------------------------------