Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I just declare an array without specifying a size? 1. create a VS C++ Pr

ID: 3924384 • Letter: H

Question

How can I just declare an array without specifying a size?

1. create a VS C++ Project, according to the steps in Appendix A in the textbook. Call the project "Sales_Bar_Chart".

2. Implement the problem specified below.

Sales Bar Chart:

Your program will ask the user to specify the number of stores in your region. Then the user will enter the sales for each store. The program must display a bar graph comparing each store’s sales. The bar graph should implement a row of asterisks, each asterisk representing $100 of sales.

Salient Features:

Your program should use:

1. for loops

2. arrays

a. new operator

b. delete operator

The Specs:

1. Your solution should prompt the user for the number of stores.

2. Your solution should prompt the user for the sales of each store.

3. The report should create a string of ‘*’ characters representing the sales,

a. Each ‘*’ would represent $100 in sales.

<<<<<< Here is my program >>>>>>>

#include

using namespace std;

int main()
{
   int sales[5]; // need an array that has no set value
   int sale = 0;
   int stores;

   cout << "How many stores do you have? ";
   cin >> stores;

   for (int i = 0; i < 5; i++)
   {
       cout << "Sales for store #" << i + 1 << ":";
       cin >> sale;
       sales[i] = sale / 100;
   }

   cout << "   SALES BAR CHART ";
   cout << "---------------------- ";
   cout << "    (Each * = $100) ";

   for (int count = 0; count < 5; count++)
   {
       cout << "Store " << count + 1 << ": ";
       for (int stars = 0; stars < sales[count]; stars++)
       {
           cout << "*";
       }
       cout << endl;
   }

   system("pause");
   return 0;
}

Explanation / Answer

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files
#include <string>

using namespace std;

int main() // driver method
{

   int sale = 0; // required initialisations
   int stores;
   int sales[stores]; // dynamic store array by getting the size from the user

   cout << "How many stores do you have? "; // prompt for the user to enter the number of stores the user has
   cin >> stores;

   for (int i = 0; i < stores; i++) // iterating over the loop of number of stores for the user
   {
       cout << "Sales for store #" << i + 1 << ":"; // printing the prompt
       cin >> sale; // getting the sales for the stores respectively
       sales[i] = sale / 100; // calculating for the display
   }

   cout << "   SALES BAR CHART "; // setting the data for the console
   cout << "---------------------- ";
   cout << "    (Each * = $100) ";

   for (int count = 0; count < stores; count++) // iterating over the loop to return the data
   {
       cout << "Store " << count + 1 << ": ";
       for (int stars = 0; stars < sales[count]; stars++) // based on the sales printing the number of symbols
       {
           cout << "*";
       }
       cout << endl;
   }
   system("pause");
   return 0;
}

OUTPUT :

How many stores do you have? 5
Sales for store #1:100
Sales for store #2:1000
Sales for store #3:2500
Sales for store #4:2000
Sales for store #5:1600
   SALES BAR CHART
----------------------
    (Each * = $100)
Store 1: *
Store 2: **********
Store 3: *************************
Store 4: ********************
Store 5: ****************


Hope this is helpful.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote