I need to convert this code from C to C++
Chapter3: Data Representation
Section: Chapter Questions
Problem 1VE
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;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc45a61cd-259f-4034-96ab-adfb5c1cf9d8%2F01262a49-7962-405a-bd09-f287ce0b6be2%2Ftma3o4_processed.png&w=3840&q=75)
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;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc45a61cd-259f-4034-96ab-adfb5c1cf9d8%2F01262a49-7962-405a-bd09-f287ce0b6be2%2Fwugvv54_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![New Perspectives on HTML5, CSS3, and JavaScript](https://www.bartleby.com/isbn_cover_images/9781305503922/9781305503922_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr