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

12.19 Ch 9 Program: Data visualization (C) In C (1) Prompt the user for a title

ID: 3597880 • Letter: 1

Question

12.19 Ch 9 Program: Data visualization (C)

In C

(1) Prompt the user for a title for data. Output the title. (1 pt)


Ex:


(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)

Ex:


(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in an array of strings. Store the integer components of the data points in an array of integers. (4 pts)

Ex:


(4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point.

If entry has no comma

Output: Error: No comma in string. (1 pt)

If entry has more than one comma

Output: Error: Too many commas in input. (1 pt)

If entry after the comma is not an integer

Output: Error: Comma not followed by an integer. (2 pts)


Ex:


(5) Output the information in a formatted table. The title is right justified with a width of 33. Column 1 has a width of 20. Column 2 has a width of 23. (3 pts)

Ex:


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

Ex:

Explanation / Answer

// DataVisualization.cpp : Defines the entry point for the console application.

//

#include "stdafx.h" //header work in visual studio

#include<iostream>

#include<string>

#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 */

cout << "Enter a title for the data: " << endl;

getline(cin, title);

/*Display statement*/

cout << "You entered: " << title<<endl;

/*Get the input */

cout << "Enter the column1 header: " << endl;

getline(cin, header1);

/*Display statement*/

cout << "You entered:" <<header1<< endl;

/*Get the input */

cout << "Enter the column2 header: " << endl;

getline(cin, header2);

/*Display statement*/

cout << "You entered:" << header2 << endl;

/*Get the input */

cout << "Enter a data point(-1 to stop input):";

getline(cin, value);

if (value == "-1") {

exit(0);

}else{

/*Declare calculatecommaCount 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;

}

}

}

/*Display statement*/

cout << right << setw(33) << endl;

cout << left << setw(20) << header1 << "|" << right << setw(23) << header2 << endl;

cout << "-------------------------------------" << endl;

int j = 0;

while (j < datastring.size()) {

cout << left << setw(20) << datastring[j] << "|" << setw(23) << datainteger[j] << endl;

j++;

}

cout << endl;

cout << endl;

/*Display statement*/

for (int k = 0; k < datastring.size(); k++) {

cout << datastring[k] << " ";

for (int j = 0; j < datainteger[k]; j++) {

cout << "*";

}

cout << endl;

}

system("pause");

return 0;

}

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