Page 1 of 1

11.21.1: Ch 9 Program: Data visualization (C) , needs to be in C programming **do not use C++** *PLEASE TEST CODE TO WOR

Posted: Sun May 15, 2022 10:10 am
by answerhappygod
11.21.1: Ch 9 Program: Data visualization (C) , needs to be
in C programming **do not use C++**
*PLEASE TEST CODE TO WORK !
my code: need to be fixed NO SCREENSHOTS OF CODE
PLEASE POST CODE TO COPY ONLY!
Im using zybooks and need to alter the code to complete
assignments need to clear off all highlighted errors
please test to make sure it works. please ensure to
correct spaces and new lines
the update code that was altered for me : correct
spacing issues code below: i cant seem to figure out
what to do to fix
fix my output to match that of the Expected
output!
code:
// C program to visualize data
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// this method validates the user input
int stringSplitterPlusAnalyzer(char dataPoint[], char dataString[],
char dataInt[])
{
// set count for commas to 0
int commaDetected = 0;

// now, count number of commas in the input
for(int i=0; i<strlen(dataPoint); i++){
if(dataPoint == ','){
commaDetected++;
}
}

// check for count and then return relevent value
if(commaDetected > 1){
return commaDetected;
}
else if(commaDetected == 0){
return -1;
}

// now, if valid input then extract name and points from the user
input
int fstWord = 0;
int secWord = 0;

dataPoint[strlen(dataPoint) - 1] = '\0';

// extract name
for(int k=0; k<strlen(dataPoint); k++){
if(dataPoint[k] != ','){
dataString[fstWord] = dataPoint[k];
++fstWord;
}
else
{
dataString[fstWord] = '\0';
break;
}
}

// extract points
int statementUnlocker;
for(int j=0; j<strlen(dataPoint); j++){
if(dataPoint[j] == ','){
statementUnlocker = 1;
continue;
}

if(statementUnlocker == 1){
if(dataPoint[j] != ' '){
dataInt[secWord] = dataPoint[j];
secWord++;
}
}
}

dataPoint[strlen(dataInt)] = '\0';
return 1;
}
// Driver function
int main(void)
{
// declare char arrays for table's title and columns names
char userTitle[50];
char columnHeader1[50];
char columnHeader2[50];
int numNovels = 0;

// these array will store names of column 1 and count of column
2
// here we can visualize 100 records (user can select size as per
the choice)
char name[100][50];
int number[100];

// now, prompt user to enter table title
printf("Enter a title for the data:\n");
fgets(userTitle, 50, stdin);
printf("You entered: %s\n", userTitle);

// now, prompt user to enter column 1 name
printf("Enter the column 1 header:\n");
fgets(columnHeader1, 50, stdin);
printf("You entered: %s\n", columnHeader1);

// now, prompt user to enter column 2 name
printf("Enter the column 2 header:\n");
fgets(columnHeader2, 50, stdin);
printf("You entered: %s\n", columnHeader2);

// declare char arrays for reading user input
char dataPoint[50];
char dataString[50];
char dataInt[50];
int returnValue;
int index = 0;

// loop until user enters -1
while(100)
{
// enter input
// the format of input will name followed by comma followed by a
number
printf("Enter a data point (-1 to stop input):\n");
fgets(dataPoint, 50, stdin);

// check if input is -1 then break the loop
if(atoi(dataPoint) == -1){
break;
}

// calling function that will validate the user input and then
return an integer value
returnValue = stringSplitterPlusAnalyzer(dataPoint, dataString,
dataInt);

// check the returned value and then print the relevent error
message
if(returnValue == -1)
{
printf("Error: No comma in string.\n\n");
}
else if(returnValue > 1){
printf("Error: Too many commas in input.\n\n");
}
else if(!isdigit(dataInt[0])){
printf("Error: Comma not followed by an integer.\n\n");
}

// if the returned value is 1, it means user input is in the
correct format
else
{
// print name and points
printf("Data string: %s\n", dataString);
printf("Data integer: %s\n\n", dataInt);

// store name and points to respective arrays
strcpy(name[index], dataString);
number[index] = atoi(dataInt);
index++;
}

// set dataString and dataInt to empty strings
strncpy(dataString,"",sizeof(dataString));
strncpy(dataInt,"",sizeof(dataInt));
}

// once the user enters -1,
// remove a new line character from title and column headers using
strtok
// because, fgets inserts a new line character in the user
input
strtok(userTitle, "\n");
strtok(columnHeader1, "\n");
strtok(columnHeader2, "\n");

// now, we will print the data in a tabular format
// print title(right justified), column 1 header(left justified),
and column 2 header(right justified)
printf("\n%33s\n", userTitle);
printf("%-20s|%23s\n", columnHeader1,columnHeader2);
printf("--------------------------------------------\n");
// print values in the table in the same format
for(int i=0; i<index; i++){
printf("%-20s|%23d\n", name,number);
}

// now, we will print histogram
printf("\n");
for(int i=0; i<index; i++)
{
// print name
printf("%20s ", name);

// print *
for(int j=0; j<number; j++){
printf("*");
}
printf("\n");
}
return 0;
}

11 21 1 Ch 9 Program Data Visualization C Needs To Be In C Programming Do Not Use C Please Test Code To Wor 1
11 21 1 Ch 9 Program Data Visualization C Needs To Be In C Programming Do Not Use C Please Test Code To Wor 1 (42.25 KiB) Viewed 34 times
11.21 Ch 9 Program: Data visualization (C) (1) Prompt the user for a title for data. Output the title. (1 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored (2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt) Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels (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: Enter a data point (-1 to stop input): Jane Austen, 6 Data string: Jane Austen Data integer: 6 (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: Enter a data point (-1 to stop input): Ernest Hemingway 9 Error: No comma in string. Enter a data point (-1 to stop input): Ernest, Hemingway, 9 Error: Too many commas in input. Enter a data point (-1 to stop input): Ernest Hemingway, nine Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Ernest Hemingway, 9 Data string: Ernest Hemingway Data integer: 9 (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) a ( Ex: Number of Novels Authored Author name 1 Number of novels Jane Austen Charles Dickens Ernest Hemingway I Jack Kerouac | F. Scott Fitzgerald | Mary Shelley Charlotte Bronte | Mark Twain Agatha Christie | Ian Flemming J.K. Rowling Stephen King Oscar Wilde 6 20 9 22 8 7 5 11 73 14 14 54 1 1 (6) Output the information as a formatted histogram. Each name is right justified with a width 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 + tt ******* ++++++ 36409020371 54 Xy

Latest submission - 12:20 AM CDT on 05/08/22 Total score: 6/17 Only show failing tests Download this submission Compiler warnings main.c: In function 'main': main.c: 74: 5: warning: unused variable 'numNovels' [-Wunused-variable] [ 74 | int numNovels = 0; 1 ANNNNNN 1: Compare output A 1/1 Input Number of Novels Authored blank blank -1 Your output correctly starts with Enter a title for the data: You entered: Number of Novels Authored 2: Compare output A 1/1 Input Number of Novels Authored Author name Number of novels -1 Enter a title for the data: You entered: Number of Novels Authored Your output correctly starts with Enter the column 1 header: You entered: Author name Enter the column 2 header: You entered: Number of novels 3: Compare output A 0/4 Output differs. See highlights below. Special character legend Input Number of Novels Authored Author name Number of novels Jane Austen, 6 -1 Your output starts with b'Enter a title for the data: \nyou entered: Number of Novels Autho Enter a title for the data:d You entered: Number of Novels Authorede لی Enter the column 1 header: You entered: Author named Expected output starts with Enter the column 2 header: You entered: Number of novelse e Enter a data point (-1 to stop input): Data string: Jane Austen Data integer: 6 4: Compare output a 1/1 Input Number of Novels Authored Author name Number of novels Ernest Hemingway 9 Ernest Hemingway 9 Ernest Hemingway, 9 -1 Enter a title for the data: You entered: Number of Novels Authored Enter the column 1 header: You entered: Author name Enter the column 2 header: You entered: Number of novels Your output correctly starts with Enter a data point (-1 to stop input): Error: No comma in string. Enter a data point (-1 to stop input): Error: No comma in string. Enter a data point (-1 to stop input): Data string: Ernest Hemingway Data integer: 9

5: Compare output A 1/1 Input Number of Novels Authored Author name Number of novels F, Scott Fitzgerald, 8 F. Scott, Fitzgerald, 8 F. Scott Fitzgerald, 8 -1 Enter a title for the data: You entered: Number of Novels Authored Enter the column 1 header: You entered: Author name Enter the column 2 header: You entered: Number of novels Your output correctly starts with Enter a data point (-1 to stop input): Error: Too many commas in input. Enter a data point (-1 to stop input): Error: Too many commas in input. Enter a data point (-1 to stop input): Data string: F. Scott Fitzgerald Data integer: 8 6: Compare output 2/2 Input Number of Novels Authored Author name Number of novels Agatha Christie, seventythree Agatha Christie, seventythree Agatha Christie, seventythree Agatha Christie, 73 -1 Enter a title for the data: You entered: Number of Novels Authored Enter the column 1 header: You entered: Author name Enter the column 2 header: You entered: Number of novels Your output correctly starts with Enter a data point (-1 to stop input): Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Data string: Agatha Christie Data integer: 73 7: Compare output A 0/3 Output differs. See highlights below. Special character legend Input Number of Novels Authored Author name Number of novels Jane Austen, 6 Charles Dickens, 20 Ernest Hemingway 9 Ernest Hemingway 9 Ernest Hemingway, 9 Jack Kerouac, 22 F, Scott Fitzgerald, 8 F. Scott, Fitzgerald, 8 F. Scott Fitzgerald, 8 Mary Shelley, 7 Charlotte Bronte, 5 Mark Twain, 11 Agatha Christie, seventythree Agatha Christie, seventythree Agatha Christie, seventythree Agatha Christie, 73 Ian Flemming, 14 J.K. Rowling, 14 Stephen King, 54 Oscar Wilde, 1 -1

Agatha Christie, le, seventythree Agatha Christie, 73 Ian Flemming. 14 J.K. Rowling, 14 Stephen King, 54 Oscar Wilde, 1 -1 b'Enter a title for the data: \nyou entered: Number of Novels Autho Your output starts With Enter a title for the data: You entered: Number of Novels Authorede Enter the column 1 header: You entered: Author named Enter the column 2 header: You entered: Number of novelse e Enter a data point (-1 to stop input): Data string: Jane Austend Data integer: 64 Enter a data point (-1 to stop input): Data string: Charles Dickens! Data integer: 202 Enter a data point (-1 to stop input): Error: No comma in string. Enter a data point 1-1 to stop input): Error: No comma in string. Enter a data point (-1 to stop input): Data string: Ernest Hemingway Data integer: 9 Enter a data point (-1 to stop input): Data string: Jack Kerouaced Data integer: 224 Enter a data point 1-1 to stop input): Error: Too many commas in input. Enter a data point (-1 to stop input): Error: Too many commas in input. Enter a data point (-1 to stop input): Data string: F. Scott Fitzgeralde Data integer: 84 Enter a data point 1-1 to stop input): Data string: Mary Shelleye Data integer: 74 Enter a data point (-1 to stop input): Data string: Charlotte Bronted Data integer: 54 Expected output starts with Enter a data point (-1 to stop input): Data string: Mark Twain Data integer: 114 Enter a data point (-1 to stop input): 4 Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Error: Comma not followed by an integer. e Enter a data point (-1 to stop input): Data string: Agatha Christie Data integer: 734 Enter a data point (-1 to stop input): Data string: Ian Flemminge Data integer: 142 Enter a data point 1-1 to stop input): Data string: J.K. Rowlinge : Data integer: 144 e Enter a data point (-1 to stop input): Data string: Stephen King Data integer: 544 Enter a data point (-1 to stop input): Data string: Oscar Wilde Data integer: 14 Enter a data point (-1 to stop input):2 Number of Novels Authorede Author name I Number of novels Jane Austen Charles Dickens Ernest Hemingway 1 Jack Kerouac F. Scott Fitzgerald | Mary Shelley Charlotte Bronte 1 Mark Twain Agatha Christie Ian Flemming J.K. Rowling Stephen King Oscar Wilde 62 20 9 9 22e 84 7 5e 11. 732 14e 144 544 1 1

8: Compare output A 0/2 Output differs. See highlights below. Special character legend loput Number of Novels Authored Author name Number of novels Jane Austen, 6 Charles Dickens, 20 Ernest Hemingway 9 Ernest Hemingway 9 Ernest Hemingway, 9 9 Jack Kerouac, 22 F, Scott Fitzgerald, 8 F. Scott, Fitzgerald, 8 F. Scott Fitzgerald, 8 Mary Shelley, 7 Charlotte Bronte, 5 Mark Twain, 11 Agatha Christie, seventythree Agatha Christie, seventythree Agatha Christie, seventythree Agatha Christie, 73 Ian Flemming. 14 J.K. Rowling, 14 Stephen King, 54 Oscar Wilde, i -1 Number of Novels Authored\nAuthor name Your output ends with | Nu Number of Novels Authorede Author name 1 Number of novelse Jane Austen Charles Dickens Ernest Hemingway Jack Kerouac I F. Scott Fitzgerald | Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming 1 J.K. Rowling 1 Stephen King Oscar Wilde 64 200 9 22 80 74 54 lle 73 14 144 54 le Expected output ends with 冲冲冲冲冲冲冲冲冲巴 古古古· *** 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 te ttttttt 9: Compare output a 0 / 2 Output differs. See highlights below. Special character legend Input Number of Musicals Written Author name Number of musicals Stephen Sondheim, 19 Leonard Bernstein, 8 Elton John, 8 Andrew L Webber, 17 Galt MacDermot, 8 Jonathan Larson, 2 John Kander, 25 Alain Boublil, 3 -1 Number of Musicals Written\nauthor name 1 Numbe Your output ends with Number of Musicals Written Author name 1 Number of musicalse Stephen Sondheim Leonard Bernstein Elton John Andrew L Webber Galt MacDermot Jonathan Larson John Kander Alain Boublil 194 8e 82 17e 8 2 254 34 1 Expected output ends with 1 1 te ** Stephen Sondheim ++++****** Leonard Bernstein ******** Elton John ++++++++ Andrew L Webber ****** Galt MacDermot ******** Jonathan Larson ** John Kander Alain Boublil *** ttt