I need to convert this code from C to C++

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 1VE
icon
Related questions
Question

I need to convert this code from C to C++

int main()
{
char number[2000];
FILE *fptr;
if ((fptr = fopen("datafile1.txt","r")) == NULL)
{
printf("Error! opening file");
// Program exits if the file pointer returns NULL.
return(1);
}
if (fgets(number,2000,fptr) != NULL)
fclose(fptr);
printf("\n File before sorting is \n\n %s \n\n", number);
printf("Frequencies are as follows:\n\n");
char temp;
int i, j;
int n= strlen(number);
freqCount(number, n);
return 0;
}
Transcribed Image Text:int main() { char number[2000]; FILE *fptr; if ((fptr = fopen("datafile1.txt","r")) == NULL) { printf("Error! opening file"); // Program exits if the file pointer returns NULL. return(1); } if (fgets(number,2000,fptr) != NULL) fclose(fptr); printf("\n File before sorting is \n\n %s \n\n", number); printf("Frequencies are as follows:\n\n"); char temp; int i, j; int n= strlen(number); freqCount(number, n); return 0; }
//sort datafile1 frequency
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*function prints frequency of list*/
void freqCount(char list[], int size){
int freq[size];
int count, j, i = 0;
for(i=0; i<size; i++){
freq[i]= -1;
//count frequencies
for(j=0; j<size; j++){
//count each number at least once
count = 1;
for(i=j+1; i<size; i++){
//compare values
if(list[j] == list[i]){
count++;
//if repeated set repeated numbers' freq to 0
freq[i]=0;
}
}
//store each frequency once
//if freqlj]!=0 then that number hasn't been recorded yet
if(freqlj) != 0}{
freq[j]=count;
}
}
//print freqs
for(j=0; j<size; j++){
if(freqlj]!=0){
printf(""%c' is repeated %d times. \n\n", list[j],freq[j]);
return;
Transcribed Image Text://sort datafile1 frequency #include <stdio.h> #include <stdlib.h> #include <string.h> /*function prints frequency of list*/ void freqCount(char list[], int size){ int freq[size]; int count, j, i = 0; for(i=0; i<size; i++){ freq[i]= -1; //count frequencies for(j=0; j<size; j++){ //count each number at least once count = 1; for(i=j+1; i<size; i++){ //compare values if(list[j] == list[i]){ count++; //if repeated set repeated numbers' freq to 0 freq[i]=0; } } //store each frequency once //if freqlj]!=0 then that number hasn't been recorded yet if(freqlj) != 0}{ freq[j]=count; } } //print freqs for(j=0; j<size; j++){ if(freqlj]!=0){ printf(""%c' is repeated %d times. \n\n", list[j],freq[j]); return;
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr