Exercise (a): In inputting and outputting the name, you were asked NOT to use a bracketed subscript. Why is a bracketed subscript unnecessary? (b) Would using name[pos] work for inputting the name? Why or why not? (c) Would using name[pos] work for outputting the name? Why or why not? Try them both and see.
a)
b)
c)
// You don't need braces because you are using pointers.
#include <iostream>
using namespace std;
const int MAXNAME = 10;
int main() {
int pos;
char* name;
int* one;
int* two;
int* three;
int result;
// Fill in code to allocate the integer variable one here
one = new int[1];
// Fill in code to allocate the integer variable two here
two = new int[1];
// Fill in code to allocate the integer variable three here
three = new int[1];
// Fill in code to allocate the character array pointed 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;
for (pos = 0; pos < MAXNAME; pos++, name++) {
cin >> *name;
// Fill in code to read a character into the name array
// WITHOUT USING a bracketed subscript
}
name -= MAXNAME;
cout << "Hi ";
for (pos = 0; pos < MAXNAME; pos++, name++) {
cout << *name;
// Fill in code to 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;
}