This program must be written in C++: Fill in the code below as indicated in the
ID: 3842510 • Letter: T
Question
This program must be written in C++:
Fill in the code below as indicated in the comments. This program demonstrates the use of dynamic variables.
#include <iostream>
using namespace std;
const int MAXNAME = 10;
{
int pos, result;
char *name = nullptr;
int *one = nullptr;
int *two = nullptr;
int *three = nullptr;
// allocate the character array pointed to by name
// and read the characters into the name array
// WITHOUT USING a bracketed subscript
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;
// print the array characters one at a time
// WITHOUT USING a bracketed subscript
// allocate the integer variables one, two, three
// 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
// calculate the sum of the three numbers, store it in result,
// then output those three numbers and their sum
// deallocate one, two, three and name
return 0;
}
Explanation / Answer
I have included your required minute code which you can easily understand.
#include <iostream>
using namespace std;
const int MAXNAME = 10;
{
int pos, result;
char *name = nullptr;
int *one = nullptr;
int *two = nullptr;
int *three = nullptr;
name = new char[MAXNAME];// allocate the character array pointed to by name
for ( pos = 0; pos < MAXNAME; pos++)
cin >> name;//name[MAXNAME];
// and read the characters into the name array
// WITHOUT USING a bracketed subscript
cout << "Enter last name with exactly 10 characters."
<< endl;
cout << "If name has < 10 characters, repeat last letter. "
<< endl << "Blanks at the end do not count." << endl;
cout << "Hi ";
for ( pos = 0; pos < MAXNAME; pos++)
cout << &name;
// print the array characters one at a time
// WITHOUT USING a bracketed subscript
int *ptr1= one;
int *ptr2= two;
int *ptr3= three;
cin >> *one >> *two >> *three;
cout << "The three numbers are " << endl;
cout << *ptr1 << endl;
cout << *ptr2 << endl;
cout << *ptr3 << endl;
// allocate the integer variables one, two, three
// 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
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;
// calculate the sum of the three numbers, store it in result,
// then output those three numbers and their sum
delete one;
delete two;
delete three;
delete name;
// deallocate one, two, three and name
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.