-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicVars.cpp
55 lines (48 loc) · 1.76 KB
/
DynamicVars.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
// This program demonstrates the use of dynamic variables
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
const int MAXNAME = 10;
int main() {
int pos, result;
char* name = nullptr;
int* one = nullptr;
int* two = nullptr;
int* three = nullptr;
// Fill in code to allocate the integer variable one here
one = new int;
// Fill in code to allocate the integer variable two here
two = new int;
// Fill in code to allocate the integer variable three here
three = new int;
// Fill in code to allocate the character array pointed to by name
name = new char[MAXNAME];
cout << "Enter your last name with exactly 10 characters." << endl;
cout << "If your name has < 10 characters, repeat last letter. " << endl
<< "Blanks at the end do not count." << endl;
for (pos = 0; pos < MAXNAME; pos++) {
cin >> *(name + pos);
}
cout << "Hi ";
for (pos = 0; pos < MAXNAME; pos++) {
cout << *(name + pos);// Fill in code to a print a character from the name array
}
// WITHOUT USING a bracketed subscript
cout << endl << "Enter three integer numbers separated by blanks" << endl;
cin >> *one >> *two >> *three;
// Fill in code to input three numbers and store them in the
// dynamic variables pointed to by pointers one, two, and three.
// You are working only with pointer variables
//echo print
cout << "The three numbers are " << endl;
cout << *one << " " << *two << " " << *three << endl;
// Fill in code to output those numbers
result = *one + *two + *three;// Fill in code to calculate the sum of the three numbers
cout << "The sum of the three values is " << result << endl;
// Fill in code to deallocate one, two, three and name
delete one;
delete two;
delete three;
delete[] name;
return 0;
}