-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.cpp
More file actions
199 lines (153 loc) · 3.32 KB
/
Copy pathpractice.cpp
File metadata and controls
199 lines (153 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include <iostream>
#include <cmath>
using namespace std;
int factorial(int n){
int facto = 1;
for(int i = 1; i< n;i++){
facto *= i;
}
return facto;
}
int printhello(){
cout << "hello\n";
return 5;
}
void myFunction(){
cout << "I just got exeuted!";
};
class Employee{
private:
int salary;
public:
Employee(int s){
salary = s;
}
//Delare friend function
friend void displaySalary(Employee emp);
};
void displaySalary(Employee emp){
cout << "Salary : " << emp.salary;
};
int main(){
cout << "hello world" << endl;
int age;
age = 17;
if (age > 18){
cout << "your a major" << endl;
}else{
cout << "your a minor" << endl;
}
char grade = 'A';
int value = grade;
cout << value << "\n";
int age2 = 25;
cout << sizeof(age2) << endl;
// int age3;
// cout << "enter the age: ";
// cin >> age3;
// cout << "the age is : " << age3 << endl;
cout << (5/(float)2) << endl;
cout << !(5 < 3) << endl;
int n = 23;
cout << (n > 0 ? "positive" : "negetive") << endl;
int n4 = 4;
for(int i = 1;i <=n4 ;i++){
int m = 10;
for (int i = 1;i<=m;i++){
cout << "*" ;
}
cout << endl;
}
int a = 4;
for(int i = 0 ;i<a ; i++){
for(int j = 0;j < i+1;j++){
cout << "*";
}
cout << endl;
}
printhello();
cout << factorial(3) << endl;
cout << endl;
cout << sqrt(64) << endl;
cout << round(2.6) << endl;
cout << log(2) << endl;
cout << endl;
// switch statments
int day = 2;
switch(day){
case 1 :
cout << "Monday" << endl;
break;
case 2:
cout << "tuesday" << endl;
break;
case 3:
cout << "wednesday" << endl;
}
for(int i = 1; i <= 3; i++){
for(int j = 1;j<=3;j++){
cout << i*j << " ";
}
cout << "\n";
}
// for each loop
int myNumbers[5] = {10,20,30,40,50};
for (int i : myNumbers){
cout << i << endl;
}
cout << endl;
// loop through a string
string word = "hello";
for (char c : word){
cout << c ;
}
cout << endl;
for (int i = 1; i <= 10; i = i + 2) {
cout << i << " ";
}
cout << endl;
int myNumbers2[5] = {10,20,30,40,50};
for (int i = 0; i < sizeof(myNumbers2)/sizeof(myNumbers2[0]);i++){
cout << myNumbers2[i] << endl;
}
cout << endl;
//loop through a multi dimensional array
string letters[2][4] = {
{ "A","B","C","D"},
{"E","F","G","H"}
};
for (int i = 0;i < 2;i++){
for (int j =0;j < 4;j++){
cout << letters[i][j] << " ";
}
}
cout << endl;
// structure
struct { // Structure declaration
int myNum; // Member (int variable)
string myString; // Member (string variable)
} myStructure; // Structure variable
myStructure.myNum = 1;
myStructure.myString = "Hello World!";
cout << myStructure.myNum << endl;
cout << myStructure.myString << endl;
// creating refernces
// & it is used for refernce
string food = "pizza";
string &meal = food; //refernce to food
cout << food << "\n";
cout << meal << "\n";
cout << endl;
// deferncence
string car = "bmw";
string* ptr = &food;
cout << ptr << endl;
cout << *ptr << endl;
// function
myFunction();
cout << 101/2 << endl;
cout << endl;
Employee myEmp(50000);
displaySalary(myEmp);
return 0;
}