Question: c++ using a command line arguments program can be invoked with zero, one, or two program parameters. The first program parameter is the input file

c++

using a command line arguments program can be invoked with zero, one, or two program parameters. The first program parameter is the input file name. The second parameter is the output file name. Sample command lines together with corresponding actions by program p04 are shown below. Boldfaced type indicates data entered at the keyboard by the user.

example:

Enter the first input file name: i04.dat

Enter the output file name: o04.dat

--

File i04.dat contains values of for code fragment 4. Program p04 reads the input file and produces output for that file. The input file consists of a sequence of integers. Integers are separated by white space. White space is one or more characters from the set that includes a blank character, a newline character, or a tab character.

example of input file:

0 2 4 8 16 32 64 128 256

--

print program results to an output file.

1. Print a line identifying the code fragment. For example, this code fragment is identified as Code Fragment 4

2. Put your output in three columns. Label the first column n, the second column Analytical and the third column Empirical. Produce values of () for each code fragment. One line is printed for each value of read. Write the value of in the column labeled n. Write the value of () computed by the designated analytical function, af4, in the column labeled Analytical. Write the value of () computed by the selected empirical function, ef4, in the column titled Empirical. Right justify and align data produced in rows with their corresponding columns.

--

//function for af4

int af4(int n){return 2 + 4n + 2n.log2m}

//function for ef4

int ef4(int n){

int t=0;

int i = 0; t++;

while(i

int m = n; t++;

while(m>1){t++;

m = m/2; t++;

} t++;

i++; t++

}

return t;

}

---

//to double check ef4 and af4 are correct.

fragment 4 analysis

c++ using a command line arguments program can be invoked with zero,

int i 0 while(i1) Line Code Cost n-1o1-in n-1o1-in n-1o1-in 2 while(i1) 1-0 7 n-1o1-in 1 Total 2+4n+2n.log2m So, T(n) 24n2n.logm int i 0 while(i1) Line Code Cost n-1o1-in n-1o1-in n-1o1-in 2 while(i1) 1-0 7 n-1o1-in 1 Total 2+4n+2n.log2m So, T(n) 24n2n.logm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!