Question

In: Computer Science

use C++ (6) Output the information as a formatted histogram. Each name is right justified with...

use C++

(6) Output the information as a formatted histogram. Each name is right justified with a setw() value of 20. (4 pts)

Ex:

         Jane Austen ******
     Charles Dickens ********************
    Ernest Hemingway *********
        Jack Kerouac **********************
 F. Scott Fitzgerald ********
        Mary Shelley *******
    Charlotte Bronte *****
          Mark Twain ***********
     Agatha Christie *************************************************************************
        Ian Flemming **************
        J.K. Rowling **************
        Stephen King ******************************************************
         Oscar Wilde *

Solutions

Expert Solution

#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<iomanip>
using namespace std;
int main() {
/*
* Declaration of title as string type
*/
string title;
/*
* Declaration of datastring as string type of vector
*/
vector < string > datastring;
/*
* Declaration of datainteger as string type of vector
*/
vector < int > datainteger;
/*
* Declaration of header1,header2,value as string type
*/
string header1, header2, value;
/*
* Get the input entered by the user
*/
cout << "Enter a title for the data:" << endl;
getline(cin, title);
/*
* Display statement entered by the user
*/
cout << "You entered: " << title << endl << endl;
/*
* Get the input entered by the user
*/
cout << "Enter the column 1 header:" << endl;
getline(cin, header1);
/*
* Display statement entered by the user
*/
cout << "You entered: " << header1 << endl << endl;
/*
* Get the input entered by the user
*/
cout << "Enter the column 2 header:" << endl;
getline(cin, header2);
/*
* Display statement entered by the user
*/
cout << "You entered: " << header2 << endl << endl;
/*
* Get the input entered by the user until the user enters -1
*/
while (true) {
cout << "\nEnter a data point (-1 to stop input):" << endl;
getline(cin, value);
if (value == "-1") {
break;
} else {
/*
   * Declare calculate commaCount as type of integer
   */
int calculatecommaCount = 0;
int i = 0;
/*
   * Iterate the loop
   */
while (i < value.length()) {
if (value[i] == ',') {
calculatecommaCount++;
}
i++;
}
if (calculatecommaCount == 0) {
cout << "Error: No comma in string." << endl;
} else if (calculatecommaCount > 1) {
cout << "Error: Too many commas in input." << endl;
} else {
/*
       * find the string and integer from datapoints
       */
string firstPoint = value.substr(0, value.find(","));
string secondPoint = value.substr(value.find(",") + 1, value.length() - 1);
firstPoint.erase(0, firstPoint.find_first_not_of(' '));
secondPoint.erase(0, secondPoint.find_first_not_of(' '));
int countNumbers = 0;
for (int i = 0; i < secondPoint.length(); i++) {
if (secondPoint[i] >= '0' && secondPoint[i] <= '9') {
countNumbers++;
}
}
/*Display statement*/
if (countNumbers == secondPoint.length()) {
datainteger.push_back(atoi(secondPoint.c_str()));
datastring.push_back(firstPoint);
cout << "Data string: " << firstPoint << endl;
cout << "Data integer: " << secondPoint << endl;
} else {
cout << "Error: Comma not followed by an integer" << endl;
}
}
}
}
/*
* Displaying the formatted output
*/
cout << right << setw(33) << endl;
cout << setw(20) << header1 << "|" << setw(23)<<right << header2 << endl;
cout << "-------------------------------------" << endl;
int j = 0;
while (j < datastring.size()) {
cout << setw(20) << datastring[j] << "|" << setw(23)<<right<< datainteger[j] << endl;
j++;
}
cout << endl;
cout << endl;
/*
* Displaying the output
*/
for (int k = 0; k < datastring.size(); k++) {
cout << setw(20) << right << datastring[k] << " ";
for (int j = 0; j < datainteger[k]; j++) {
cout << "*";
}
cout << endl;
}
system("pause");
return 0;
}

=========================================

Output:

====================================Thank You


Related Solutions

use c++ (5) Output the information in a formatted table. The title is right justified with...
use c++ (5) Output the information in a formatted table. The title is right justified with a setw() value of 33. Column 1 has a setw() value of 20. Column 2 has a setw() value of 23. (3 pts) Ex: Number of Novels Authored Author name | Number of novels -------------------------------------------- Jane Austen | 6 Charles Dickens | 20 Ernest Hemingway | 9 Jack Kerouac | 22 F. Scott Fitzgerald | 8 Mary Shelley | 7 Charlotte Bronte | 5...
Select any data set . Use the method of Sections 6-6 to construct a histogram and...
Select any data set . Use the method of Sections 6-6 to construct a histogram and normal quartile plot, then determine whether the data set appears to come from a normally distributed population.
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
Use the Excel output in the below table to do (1) through (6) for each ofβ0,...
Use the Excel output in the below table to do (1) through (6) for each ofβ0, β1, β2, and β3. y = β0 + β1x1 + β2x2 + β3x3 + ε     df = n – (k + 1) = 16 – (3 + 1) = 12 Excel output for the hospital labor needs case (sample size: n = 16) Coefficients Standard Error t Stat p-value Lower 95% Upper 95% Intercept 1946.8020 504.1819 3.8613 0.0023 848.2840 3045.3201 XRay (x1) 0.0386...
Write a C program that outputs a formatted header line and creates 10 children processes each...
Write a C program that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657    13653    20...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time moving down to the left (for heads) and to the right (for tails). Consider it a success if when flipping a coin, the coin lands with the head side facing up. Then the probability of a success is .5 (p=.5) and the probability of failure is .5 (q=.5) for each event of flipping a coin. In this lab you will repeat a procedure of...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time moving down to the left (for heads) and to the right (for tails). Consider it a success if when flipping a coin, the coin lands with the head side facing up. Then the probability of a success is .5 (p=.5) and the probability of failure is .5 (q=.5) for each event of flipping a coin. In this lab you will repeat a procedure of...
5. What is the skewness and kurtosis of each data set? 6. Generate a histogram plot...
5. What is the skewness and kurtosis of each data set? 6. Generate a histogram plot of each of the data sets. 7. Based on the variability of the data, what do you think the next step would be to analyze the data? Age Income 29 9315 25 6590 28 9668 27 8412 25 1654 24 2431 25 6977 19 8966 27 9327 18 3871 25 9934 19 2236 19 3035 29 2518 19 3616 19 9219 28 1090 18...
What is the output from each of the following segments of C++ code? Record the output...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT