lab using dynamic memory

below i have code where i am asked to fill in some information

#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

// Fill in code to allocate the integer variable two here

// Fill in code to allocate the integer variable three here

// Fill in code to allocate the character array pointed to by name

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 >> // Fill in code to read a character into the name array

// WITHOUT USING a bracketed subscript

cout << "Hi ";

for (pos = 0; pos < MAXNAME; pos++)

cout << // 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;

// 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;

// Fill in code to output those numbers

result = // 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

return 0;
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) You don't appear to have asked us anything. What is it that you want?
There are problems with your code, even though you don't actually ask a question about the mess.

1. the lack of code tags AND double-spacing each line make your code hard to read and comment on. PLEASE learn to use code tags.

http://www.cplusplus.com/articles/jEywvCM9/

(hint: you can edit your post and add the code tags.)

2. you are not initializing the dynamic memory variables, using new or new[].

3. no need to double space each line, it makes your code harder to read and understand. Even with code tags.

4. you are missing a number of semicolons, so what should be separate code lines the compiler treats as a single statement.

5. you are missing at least one closing bracket }.

6. you start to assign a value to a variable, without any value. Or a semicolon to finish the code statement.

It takes a lot of work to get your code into a compilable (and readable) form.

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
#include <iostream>
#include <cstring>   // std::strlen : http://www.cplusplus.com/reference/cstring/strlen/
int main()
{
   // alway have enough space for the terminating null character '\0'
   // and for excessive data entry
   const int MAXNAME = 256;
   char* name { new char[MAXNAME] };

   // loop until exactly 10 characters are entered
   do
   {
      std::cout << "Enter your last name with exactly 10 characters.\n";
      std::cout << "If your name has < 10 characters, repeat last letter.\n"
                << "Blanks at the end do not count.\n: ";

      std::cin.getline(name, MAXNAME);
      std::cout << '\n';
   }
   while (std::strlen(name) < 10  || std::strlen(name) > 10);

   std::cout << "Hi, ";

   // output your C string using pointer notation
   for (size_t pos = 0; pos < std::strlen(name); pos++)
   {
      std::cout << *(name + pos);
   }
   std::cout << "\n\n";

   int* one   { new int(0) };
   int* two   { new int(0) };
   int* three { new int(0) };

   std::cout << "Enter three integer numbers separated by blanks\n: ";
   std::cin >> *one >> *two >> *three;
   std::cout << '\n';

   std::cout << "The three numbers are\n"
      << *one << ' ' << *two << ' ' << *three << '\n';

   int result { *one + *two + *three };

   std::cout << "The sum of the three values is " << result << '\n';

   // it pays to be neat, clean up after yourself
   delete[] name;

   delete one;
   delete two;
   delete three;
}

Enter your last name with exactly 10 characters.
If your name has < 10 characters, repeat last letter.
Blanks at the end do not count.
: de Blasio

Enter your last name with exactly 10 characters.
If your name has < 10 characters, repeat last letter.
Blanks at the end do not count.
: my name is a long one

Enter your last name with exactly 10 characters.
If your name has < 10 characters, repeat last letter.
Blanks at the end do not count.
: mylastname

Hi, mylastname

Enter three integer numbers separated by blanks
: 3 4 5

The three numbers are
3 4 5
The sum of the three values is 12
Topic archived. No new replies allowed.