Problem 1: Dynamic Grocery Array

Write a program that prompts the user for the total number of grocery item he/she would like to enter. Then prompt the user to enter an item's name for each position in the array. The program then prints out the array. Please include a string library. #include Don't forget to remove a dynamic array!

How many items would you like to enter? 10
1: Banana
2: Orange
3: Milk
4: Carrot
5: Chips
6: Soda
7: Bread
8: Cheese
9: Pasta
10 : Tomatoes

Note: Dynamically allocated arrays are defined as pointers and allocated using the new keyword.

For example: char* chars = new char [count ] ; would create a dynamic array of
characters. Again, Don't forget to delete the dynamic array.

Problem 2: Print Characters in String Array

Declare a string array of size 5. Prompt the user enters five strings that are stored in the array.

Write a function that prints a string in a reverse order. Call that function from the main and
output the value.

Hint: An array of string is like working with multi-dimensional array.

Enter five items.
Item 1: hello
Item 2 : C++
Item 3: Wednesday
Item 4: It's a great day
Item 5: goodbye
Reverse string.
Item 1: olleh
Item 2: ++C
Item 3: yadsendeW
Item 4: yad taerg a s' tI
Item 5: eybdoog

Note: Don't forget to include . You may only use the . length () function on a string variable to get the number of characters in a string, e.g. str. length (). . Use array
syntax on a string variable to access any char by index, e.g.: assuming a string variable named str that stores "hello", str[1] would return 'e'.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

* File:   problem1.cpp
* Author:

#include <string>
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
    // validate the input
    int size = -1;
    while (size <= 0) {
       cout << "How many items would you like to enter? ";
       cin >> size;

    // allocate dynamic array
    string * items = new string[size];...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats