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

Need this C++ program converted to C. Thanks #include <iostream> #include <strin

ID: 3843170 • Letter: N

Question

Need this C++ program converted to C. Thanks

#include <iostream>
#include <string>
#include <vector>
//FIXME: stringstream library
//FIXME: stream manipulation library
using namespace std;
int main() {

/* Type code here. */
string title, heading1, heading2, s;
vector<string> data;
vector<int> point;
cout<<"Enter a title for the data: ";
getline(cin, title);
cout<<"You entered: "<<title<<endl;
cout<<"Enter the column 1 header: ";
getline(cin, heading1);
cout<<"You entered: "<<heading1<<endl;
cout<<"Enter the column 2 header: ";
getline(cin, heading2);
cout<<"You entered: "<<heading2<<endl;
while(1){
cout<<"Enter a data point (-1 to stop input): ";
getline(cin, s);
if(s == "-1"){
break;
}
if(s.find(',') == -1){
cout<<"Error: No comma in string."<<endl;
}
else{
int commaCount = 0;
for(int i=0; i<s.length(); i++){
if(s.at(i) == ','){
commaCount++;
if(commaCount > 1){
break;
}
}
}
if(commaCount == 1){
data.push_back (s.substr(0, s.find(',')));
           point.push_back (stoi(s.substr(s.find(',')+1, s.length()-1)));
cout<<"Data string: "<<s.substr(0, s.find(','))<<endl;
cout<<"Data integer: "<<stoi(s.substr(s.find(',')+1, s.length()-1))<<endl;
}
else{
cout<<"Error: Too many commas in input."<<endl;
}
}
}
cout<<" "<<title<<" "<<endl;
cout<<heading1<<" | "<<heading2<<endl;
for(int i=0; i<data.size(); i++){
cout<<data[i]<<" | "<<point[i]<<endl;
}
for(int i=0; i<data.size(); i++){
cout<<data[i]<<" ";
for(int j=0; j<point[i]; j++){
cout<<"*";
}
cout<<endl;
}


return 0;
}

Explanation / Answer

#include <stdio>

main() {
/* Type code here. */
//string title, heading1, heading2, s;
char title[], heading1[], heading2[], s[];
int commaCount = 0,commaExists =-1,firstComma=-1;
int z=0;
int l=0;
int g=0;

//vector<string> data;
//vector<int> point;

char data[256][256];
int point[256];
char temp[256];

//cout<<"Enter a title for the data:
//getline(cin, title);
//cout<<"You entered: "<<title<<endl;
//cout<<"Enter the column 1 header: ";
//getline(cin, heading1);
//cout<<"You entered: "<<heading1<<endl;
//cout<<"Enter the column 2 header: ";
//getline(cin, heading2);
//cout<<"You entered: "<<heading2<<endl;


printf("Enter a title for the data:");
scanf("%s",&title);
printf("You entered: %s ", title);
printf("Enter the column 1 header: ");
scanf("%s",&heading1);
printf("You entered: %s ", heading1);
printf("Enter the column 2 header: ");
scanf("%s",&heading2);
printf("You entered: %s ", heading2);


while(1){
//cout<<"Enter a data point (-1 to stop input): ";
//getline(cin, s);

printf("Enter a data point (-1 to stop input): ");
scanf("%s",&s);
firstComma = -1;
commaCount = 0;
commaExists =-1;

if(s[0] == '-1'){
break;
}

for(h=0; s[h]!=' '; h++){
if(s[h] == ','){
commaExists = 1;
firstComma = h;
break;
}
}

if(commaExists == -1){
//cout<<"Error: No comma in string."<<endl;
printf("Error: No comma in string. ");
}
else{
commaCount = 1;
for(int i=firstComma+1; s[i]!=' '; i++){
if(s[i] == ','){
commaCount++;
if(commaCount > 1){
break;
}
}
}
if(commaCount == 1){
//data.push_back (s.substr(0, s.find(',')));
// point.push_back (stoi(s.substr(s.find(',')+1, s.length()-1)));
//cout<<"Data string: "<<s.substr(0, s.find(','))<<endl;
//cout<<"Data integer: "<<stoi(s.substr(s.find(',')+1, s.length()-1))<<endl;

for(i=0;s[i]!=' '&& i<firstComma;i++)
{
   data[z][i] = s[i];
}


for(m=firstComma+1;s[m]!=' ';m++){

temp[g++] = s[m];

}
g=0;

point[l] = atoi(temp);

printf("Data string: %s ",data[z]);
printf("Data integer: %d ",point[l]);

z++;
l++;
}
else{
cout<<"Error: Too many commas in input."<<endl;
}
}
}
printf(" %s ", title);
printf("%s | %s ", heading1,heading2)
for(int i=0; i<data.size(); i++){
printf("%s | %d ", data[i],point[i]);
}
for(int i=0; i<data.size(); i++){
printf("%s ",data[i]);
for(int j=0; j<point[i]; j++){
printf("*");
}
printf(" ");
}

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