-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-vs-instance.cpp
More file actions
76 lines (65 loc) · 1.25 KB
/
Copy pathclass-vs-instance.cpp
File metadata and controls
76 lines (65 loc) · 1.25 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
#include <iostream>
using namespace std;
void PrintMultiples(int num) {
for (int i = 1; i <= 10; i++) {
cout << num << " x " << i << " = " << (num * i) << endl;
}
}
void PrintStringOddEvens(string str) {
for (int i = 0; i < str.length(); i++) {
if (i % 2 == 0) {
cout << str[i];
}
}
cout << " ";
for (int i = 0; i < str.length(); i++) {
if (i % 2 != 0) {
cout << str[i];
}
}
}
int main() {
/*cout << "**** 7 ****" << endl;
PrintMultiples(7);
cout << "**** 8 ****" << endl;
PrintMultiples(8);
cout << "**** 14 ****" << endl;
PrintMultiples(14);*/
int n;
cout << "Enter the no. of test cases: " << endl;
cin >> n;
for (int i = 1; i <= n; i++) {
string str;
cout << "Enter " << i << "th string: ";
cin >> str;
PrintStringOddEvens(str);
cout << endl;
}
return 0;
}
class Person {
int age;
Person(int initialAge) {
if (initialAge > 0) {
this->age = initialAge;
}
else {
this->age = 0;
cout << "Age is not valid, setting age to 0." << endl;
}
}
void yearPasses() {
this->age++;
}
void amIOld() {
if (this->age < 13) {
cout << "You are young." << endl;
}
else if (this->age >= 13 && this->age < 18) {
cout << "You are a teenager." << endl;
}
else {
cout << "You are old." << endl;
}
}
};