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

The programing language that should be used here is C. Thanks for the help (1) P

ID: 3812898 • Letter: T

Question

The programing language that should be used here is C.

Thanks for the help

(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

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
   char title[40],col1Header[20],col2Header[20];
   printf("Enter Title of the Data: ");
   gets(title);
   printf("You Entered: ");
   puts(title);
   printf(" ");
  
   printf("Enter the Coloumn 1 Header: ");
   gets(col1Header);
   printf("You Entered: ");
   puts(col1Header);
   printf(" ");
  
   printf("Enter the Coloumn 2 Header: ");
   gets(col2Header);
   printf("You Entered: ");
   puts(col2Header);
   printf(" ");
  
   char datapoint[30];
   int result,i=0;
   char datastring[20];
   char stringdata[50];
   char datainteger[10];
   int datavalue[10];
   enter_data: do{
       printf(" Enter data point: ");
       gets(datapoint);
       if(atoi(datapoint)== -1){
           printf("Thank you");
           exit(0);
       }
       else{
           char c;
           int j = 0,count = 0,nocomma = 0;
          
          
           while(datapoint[j] != ''){
               if(datapoint[j] == ',')
               {
                   count++;
                   if(count >= 2){
                       printf(" Error: Too many comma's'");
                       goto enter_data;
                   }
                   else{
                       result = sscanf(datapoint,"%[^','],%[^',']",datastring,datainteger);
                       if(isdigit(atoi(datainteger))==0){
                           datavalue[i] = atoi(datainteger);
                           printf(" Data String = %s Data Integer = %d",datastring,datavalue[i]);
                           i++;
                       }
                       else{
                           printf(" Error: Comma not followed by integer");
                           goto enter_data;
                       }
                   }
               }
              
               j++;
              
           }
           if(count == 0){
               printf("Error: No comma's'");
               goto enter_data;
           }
          
       }
   }while(1);
   return 0;
}