subject

Convert the following C program to C++. More instructions follow the code.

#include
#include

#define SIZE 5

int main(int argc, char *argv[]) {
int numerator = 25;
int denominator = 10;
int i = 0;

/*
You can assume the files opened correctly and the
correct number of of command-line arguments were
entered.
*/
FILE * inPut = fopen(argv[1], "r");
FILE * outPut = fopen(argv[2], "w");

float result = (float)numerator/denominator;
fprintf(outPut,"Result is %.2f\n", result);

float arr[SIZE];

for( ; i < SIZE; i++) {
fscanf(inPut, "%f", &arr[i]);
fprintf(outPut, "%7.4f\n", arr[i]);
}

return 0;
}

Notice this is uses command-line arguments. I have provided an input file called num. txt that will be used when running the program. The output file is called out. txt.

Make sure you are using C++ style file I/O (FILE pointers/fopen) as well as regular I/O including the C++ style output formatting (fscanf, fprintf, formatting). Also use the C++ method of casting. The lines above that are bold are the lines that you need to convert to C++. Don't forget to add the necessary C++ statements that precede the main() function.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:00
What role do chromosomes play in inheritance?
Answers: 1
question
Computers and Technology, 23.06.2019 22:00
Technician a says engine assemblies can be mounted longitudinally in a chassis. technician b says engine assemblies can be mounted transversely in a chassis. who is correct?
Answers: 2
question
Computers and Technology, 24.06.2019 19:20
Which command suppresses the visibility of a particular row or column in a worksheet?
Answers: 1
question
Computers and Technology, 25.06.2019 03:00
Between 1932 and 1938, chester carlson developed a process that enabled a "picture" of a document to be taken and then have it reproduced on another
Answers: 1
You know the right answer?
Convert the following C program to C++. More instructions follow the code.

#include
Questions
question
Social Studies, 02.10.2019 20:00
question
Mathematics, 02.10.2019 20:00
Questions on the website: 13722361