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

Please convert this program from JAVA to C. import java.util.ArrayList; import j

ID: 3852148 • Letter: P

Question

Please convert this program from JAVA to C.

import java.util.ArrayList;
import java.util.Scanner;

public class Novels {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       ArrayList<String> dataStr = new ArrayList<String>();
       ArrayList<Integer> dataPoint = new ArrayList<Integer>();
       System.out.print("Enter a title for the data: ");
       String title = scan.nextLine();
       System.out.println("You entered: "+title);
       System.out.print("Enter the column 1 header: ");
       String header1 = scan.nextLine();
       System.out.println("You entered: "+header1);
       System.out.print("Enter the column 2 header: ");
       String header2 = scan.nextLine();
       System.out.println("You entered: "+header2);
       while(true){
       System.out.print("Enter a data point (-1 to stop input): ");
       String s = scan.nextLine();
       if(s.equals("-1")){
           break;
       }
       else{
           String str[] = s.split(",");
           if(str.length == 1){
               System.out.println("Error: No comma in string.");
           }
           else if(str.length > 2){
               System.out.println("Error: Too many commas in input.");
           }
           else {
               try{
                   int point = Integer.parseInt(str[1].trim());
                   dataPoint.add(point);
                   dataStr.add(str[0]);
                   System.out.println("Data string: "+str[0]);
                   System.out.println("Data integer: "+point);
               }catch(NumberFormatException e){
                   System.out.println("Error: Comma not followed by an integer.");
               }
           }
       }
       }

       System.out.printf("%33s ",title);
       System.out.printf("%-20s|%23s ",header1,header2);
       System.out.println("-------------------------------------");
       for(int i=0; i<dataStr.size(); i++){
           System.out.printf("%-20s|%23d ",dataStr.get(i),dataPoint.get(i));
       }
       for(int i=0; i<dataStr.size();i++){
           System.out.print(dataStr.get(i)+" ");
           for(int j=0; j<dataPoint.get(i);j++){
               System.out.print("*");
           }
           System.out.println();
       }
   }

}

Explanation / Answer

Answer:-

#include <string>
#include <vector>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>

class Novels
{
static void main(std::vector<std::wstring> &args);
};

void Novels::main(std::vector<std::wstring> &args)

{
   Scanner *scan = new Scanner(System::in);
   std::vector<std::wstring> dataStr;
   std::vector<int> dataPoint;
   std::wcout << std::wstring(L"Enter a title for the data: ");
   std::wstring title = scan->nextLine();
   std::wcout << std::wstring(L"You entered: ") << title << std::endl;
   std::wcout << std::wstring(L"Enter the column 1 header: ");
   std::wstring header1 = scan->nextLine();
   std::wcout << std::wstring(L"You entered: ") << header1 << std::endl;
   std::wcout << std::wstring(L"Enter the column 2 header: ");
   std::wstring header2 = scan->nextLine();
   std::wcout << std::wstring(L"You entered: ") << header2 << std::endl;
   while (true)
   {
   std::wcout << std::wstring(L"Enter a data point (-1 to stop input): ");
   std::wstring s = scan->nextLine();
   if (s == L"-1")
   {
       break;
   }
   else
   {

       std::vector<std::wstring> str = s.split(L",");
       if (str.size() == 1)
       {
           std::wcout << std::wstring(L"Error: No comma in string.") << std::endl;
       }
       else if (str.size() > 2)
       {
           std::wcout << std::wstring(L"Error: Too many commas in input.") << std::endl;
       }
       else
       {
           try
           {
               int point = static_cast<Integer>(boost::trim_copy(str[1]));
               dataPoint.push_back(point);
               dataStr.push_back(str[0]);
               std::wcout << std::wstring(L"Data string: ") << str[0] << std::endl;
               std::wcout << std::wstring(L"Data integer: ") << point << std::endl;
           }
           catch (const NumberFormatException &e)
           {
               std::wcout << std::wstring(L"Error: Comma not followed by an integer.") << std::endl;
           }
       }
   }
   }
   printf(L"%33s ",title);
   printf(L"%-20s|%23s ",header1,header2);
   std::wcout << std::wstring(L"-------------------------------------") << std::endl;
   for (int i = 0; i < dataStr.size(); i++)
   {
       printf(L"%-20s|%23d ",dataStr[i],dataPoint[i]);
   }
   for (int i = 0; i < dataStr.size();i++)
   {
       std::wcout << dataStr[i] << std::wstring(L" ");
       for (int j = 0; j < dataPoint[i];j++)
       {
           std::wcout << std::wstring(L"*");
       }
       std::wcout << std::endl;
   }
}

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