Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What is Accounting?

Answered: 1 week ago

Question

Define organisation chart

Answered: 1 week ago

Question

What are the advantages of planning ?

Answered: 1 week ago