-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.cpp
99 lines (77 loc) · 1.68 KB
/
test2.cpp
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
//============================================================================
// Name : test2.cpp
// Author : albert
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <string.h>
using namespace std;
class Weapon
{
public:
virtual void features()
{ cout << "Loading weapon features.\n"; }
};
class Bomb : public Weapon
{
public:
void features()
{ cout << "Loading bomb features.\n"; }
};
class Gun : public Weapon
{
public:
void features()
{ cout << "Loading gun features.\n"; }
};
class Loader
{
public:
void loadFeatures(Weapon *weapon)
{
weapon->features();
}
};
class cars
{
public:
static int cnt1;
};
int cars::cnt1 = 0;
unsigned long long int factorial(unsigned int i) {
if(i <= 1) {
return 1;
}
return i * factorial(i - 1);
}
int main()
{
char str1[20];
//char str2[20];
char *str2 = "123456789";
char c, c1;
int i = 4;
cars A1, B1;
A1.cnt1 = 10;
printf("A1.cnt1 = %d\n", A1.cnt1);
printf("B1.cnt1 = %d\n", B1.cnt1);
printf("Factorial of %d is %d\n", i, factorial(i));
printf("strlen of 123456789 = %d\n", strlen(str2));
scanf("%19s", str1);
//to skip the '\n' newline from user input
while((c=getchar())!='\n' && c!=EOF);
scanf(" %c", &c1);
//scanf("%s", str2);
printf("%s %c\n", str1, c1);
Loader *l = new Loader;
Weapon *w;
Bomb b;
Gun g;
w = &b;
l->loadFeatures(w);
w = &g;
l->loadFeatures(w);
return 0;
}