Skip to content

Commit ca89634

Browse files
authored
Add files via upload
1 parent 807f74b commit ca89634

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2624
-0
lines changed

tempCodeRunnerFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// for ( int i = 0; i < 10; i++)
2+
// {
3+
// cout<<i<<endl;
4+
// }

tut1

15.4 KB
Binary file not shown.

tut1.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include<iostream>
2+
3+
int main(){
4+
std::cout<<"Hello world";
5+
return 0;
6+
}

tut10.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
int main(){
4+
// for (int i = 0; i < 4; i++)
5+
// {
6+
7+
// if(i==2){
8+
// break;
9+
// };
10+
// cout<<i<<endl;
11+
12+
// }
13+
for (int i = 0; i < 10; i++)
14+
{
15+
16+
if(i==2){
17+
continue;
18+
}
19+
cout<<i<<endl;
20+
21+
}
22+
23+
return 0;
24+
}

tut12.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main(){
5+
int a = 3;
6+
int * b = &a; // Pointer --> the data type which stores addr of other datatypes
7+
// & --> address of operator
8+
cout<<"the address of a is "<<b<<endl;
9+
cout<<"the address of a is "<<&a<<endl;
10+
11+
//* --> dereference operator,
12+
cout<<"the address of a is "<<*b<<endl;
13+
14+
int ** c = &b;
15+
cout<<"the value of b is "<<c<<endl;
16+
cout<<"The value at address c is "<<*c<<endl;
17+
cout<<"The value at address value_at(value_at(c)) is "<<**c<<endl;
18+
return 0;
19+
}

tut13.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include<iostream>
2+
using namespace std;
3+
int main(){
4+
int marks[] = {29, 13, 41, 27, 30};
5+
cout<<marks[1]<<endl;
6+
cout<<marks[2]<<endl;
7+
8+
int Mamarks[4];
9+
Mamarks[0]=839;
10+
Mamarks[1]=8900;
11+
Mamarks[2]=2389;
12+
13+
cout<<"Marks are"<<endl;
14+
cout<<Mamarks[0]<<endl;
15+
cout<<Mamarks[1]<<endl;
16+
cout<<Mamarks[2]<<endl;
17+
// for ( int i = 0; i < 4; i++)
18+
// {
19+
// cout<<"The value of marks "<<i<<" is "<<marks[i]<<endl;
20+
// }
21+
22+
//Doing the same using while-loop
23+
// int i = 0;
24+
// while ( i < 4)
25+
// {
26+
// cout<<"The value of marks "<<i<<" is "<<marks[i]<<endl;
27+
// i++;
28+
// }
29+
30+
//Pointers and arrays
31+
int *p = marks;
32+
cout<<"the value of marks[1] is "<< *p<<endl;
33+
cout<<"the value of marks[2] is "<< *(p+1)<<endl;
34+
cout<<"the value of marks[3] is "<< *(p+2)<<endl;
35+
cout<<"the value of marks[4] is "<< *(p+3)<<endl;
36+
cout<<"the value of marks[100] is "<< *(p+10)<<endl;
37+
cout<<*(p++)<<endl;
38+
cout<<*p<<endl;
39+
cout<<*(++p)<<endl;
40+
cout<<*p<<endl;
41+
42+
43+
return 0;
44+
}

tut14.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
// typedef struct employ
5+
// {
6+
// int id;
7+
// char fav_character;
8+
// float salary;
9+
// string name;
10+
// } ep;
11+
12+
// union money
13+
// {
14+
// int rice;
15+
// char car;
16+
// float salary;
17+
18+
// };
19+
20+
21+
int main(){
22+
// ep harry;
23+
// ep aditya;
24+
25+
// harry.id = 2;
26+
// harry.fav_character = '$';
27+
// harry.salary = 900000;
28+
29+
// cout<<harry.id<<endl;
30+
// cout<<harry.salary<<endl;
31+
32+
// union money m1;
33+
// m1.rice = 1
34+
// m1.car
35+
enum meal{breakfast, dinner, lunch};
36+
meal m1 = lunch;
37+
cout<<m1;
38+
39+
40+
41+
return 0;
42+
}

tut15.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
//Function Prototypes
5+
//func-name(args)
6+
7+
int sum(int a, int b); //acceptable
8+
// int sum(int, int); //acceptable
9+
// int sum(int a, b); //unacceptable
10+
11+
void g( void );
12+
13+
14+
15+
16+
17+
int main(){
18+
int num1, num2;
19+
cout<<"enter number 1: "<<endl;
20+
cin>>num1;
21+
22+
cout<<"enter number 2: "<<endl;
23+
cin>>num2;
24+
25+
cout<<"the sum of number 1 and number 2 is:"<<sum(num1, num2)<<endl;
26+
27+
return 0;
28+
}
29+
30+
int sum(int a, int b){
31+
// formal params a and b will be taking values from actual params num1 & num2
32+
int c = a + b;
33+
}
34+
35+
void g(){
36+
cout<<"hello, good night"<<endl;
37+
}

tut16.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int sum(int a, int b){
5+
int c = a + b;
6+
return c;
7+
}
8+
//swaping using reference variables
9+
void swapointer(int* num1, int* num2){
10+
int temp = *num1;
11+
*num1 = *num2;
12+
*num2 = temp;
13+
}
14+
15+
// call by reference using c++ reference variables
16+
void swaPointerVar(int &num1, int &num2){
17+
int temp = num1;
18+
num1 = num2;
19+
num2 = temp;
20+
}
21+
22+
int main(){
23+
int n1 = 10, n2 = 6;
24+
//cout<<"the sum is "<<sum(9, 6)<<endl;
25+
cout<<"the value of num1 is " <<n1<<"the value of num2 is " <<n2<<endl;
26+
swapointer(&n1, &n2);
27+
cout<<"the value of num1 is "<<n1<<"the value of num2 is "<<n2<<endl;
28+
return 0;
29+
}

tut17.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
inline int product(int a ,int b){
5+
// static int c=0; //eexecutes once
6+
// c = c + 1; // c keeps changing
7+
return a*b;
8+
}
9+
float moneyRec(int curr_money, float factor=1.04){
10+
return curr_money * factor;
11+
}
12+
13+
int main(){
14+
// int a,b;
15+
// cout<<"enter numbers: "<<endl;
16+
// cin>>a>>b;
17+
// cout<<"the product of the numbers is "<<product(a,b);
18+
int money = 100000;
19+
cout<<"If u have "<<money<<"Rs in your bank account, you will receive "<<moneyRec(money)<<" in your account"<<endl;
20+
cout<<"VIPs: If u have "<<money<<"Rs in your bank account, you will receive "<<moneyRec(money, 1.1)<<" in your account";
21+
22+
return 0;
23+
}

tut18.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int factorial(int n){
5+
if (n<=1)
6+
{
7+
return 1;
8+
}
9+
return n * factorial(n-1);
10+
}
11+
12+
int fibonacci(int n){
13+
if (n<2)
14+
{
15+
return 1;
16+
}
17+
return fibonacci(n-1) + fibonacci(n-2);
18+
}
19+
20+
int main(){
21+
// factorial of a number
22+
// 4! = 4*3*2*1 = 24
23+
// n = n * (n-1)
24+
int a;
25+
cout<<"Enter a number:"<<endl;
26+
cin>>a;
27+
//cout<<"The factorial of " <<a<< " is "<<factorial(a)<<endl;
28+
cout<<"The factorial of " <<a<< " is "<<fibonacci(a)<<endl;
29+
return 0;
30+
}

tut19.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int sum(int a, int b){
5+
cout<<"using function with 2 args"<<endl;
6+
return a+b;
7+
}
8+
9+
int sum(int a, int b, int c){
10+
cout<<"using function with 3 args"<<endl;
11+
return a+b+c;
12+
}
13+
14+
int main(){
15+
cout<<"Sum is "<<sum(1,2)<<endl;
16+
cout<<"sum is "<<sum(5,4,3);
17+
return 0;
18+
}

tut2.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<iostream>
2+
using namespace std;
3+
// program created by me
4+
5+
/* program
6+
created
7+
by me */
8+
9+
int main(){
10+
int s = 69;
11+
cout<< "ho ho"<< s;
12+
return 0;
13+
}

tut21.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Employ
5+
{
6+
private:
7+
int a, b, c;
8+
public:
9+
int fo, e;
10+
void setdata(int a1, int b1, int c1); //declaration
11+
void getdata(){
12+
cout<<"the value of a is "<<a<<endl;
13+
cout<<"the value of c is "<<c<<endl;
14+
cout<<"the value of b is "<<b<<endl;
15+
cout<<"the value of e is "<<e<<endl;
16+
}
17+
18+
19+
};
20+
21+
void Employ :: setdata(int a1, int b1, int c1){
22+
a = a1;
23+
b = b1;
24+
c = c1;
25+
}
26+
main(){
27+
Employ saiman;
28+
//saiman.a = 00 --> will throw error as defined private
29+
saiman.e = 10;
30+
saiman.fo = 80;
31+
saiman.setdata(2, 3, 6);
32+
saiman.getdata();
33+
return 0;
34+
}

0 commit comments

Comments
 (0)