Computers and Technology

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.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:30, iamquintix
Exchanging which type of data uses the least bandwidth? music photographs video voice bandwidth- the amount of data that can be moved between two points in a set time period
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, ryleerose255
Idon’t understand the double8 coding problem. it is java
Answers: 1
image
Computers and Technology, 23.06.2019 19:00, jaymc1932
Whose task it is to ensure that the product flows logically from one step to another?
Answers: 3
image
Computers and Technology, 23.06.2019 19:00, Heyitsbrandi
Now you’re on your own. include a short summary of this section with plots in your lab report. write a matlab script file to do steps (a) through (d) below. include a listing of the script file with your report. 1 the soundsc(xx, fs) function requires two arguments: the first one (xx) contains the vector of data to be played, the second argument (fs) is the sampling rate for playing the samples. in addition, soundsc(xx, fs) does automatic scaling and then calls sound(xx, fs) to actually play the signal. mcclellan, schafer, and yoder, dsp first, 2e, isbn 0-13-065562-7. prentice hall, upper saddle river, nj 07458. c 2015 pearson education, inc. 4 mcclellan, schafer and yoder, signal processing first. prentice hall, upper saddle river, new jersey, 2003. c 2003 prentice hall. (a) generate a time vector (tt) to cover a range of t that will exhibit approximately two cycles of the 4000 hz sinusoids defined in the next part, part (b). use a definition for tt similar to part 2.2(d). if we use t to denote the period of the sinusoids, define the starting time of the vector tt to be equal to t , and the ending time as ct . then the two cycles will include t d 0. finally, make sure that you have at least 25 samples per period of the sinusoidal wave. in other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period. (b) generate two 4000 hz sinusoids with arbitrary amplitude and time-shift. x1.t / d a1 cos.2
Answers: 1
Do you know the correct answer?
Convert the following C program to C++. More instructions follow the code.

#include

Questions in other subjects:

Konu
Social Studies, 22.09.2019 21:30
Konu
Mathematics, 22.09.2019 21:30