Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write functions. a) Fibonacci number generation function b) GCD function 2. I

ID: 3609522 • Letter: 1

Question

1)     Write functions.

a)     Fibonacci number generation function

b)     GCD function

2.

In main ()

a)      Read from input file(test1.txt)twonumber at a time this two number in a single line these twonumber are

First number is for the weekday ofweek (form 1 for Monday to 5 for Friday)

Second number is the number ifengine parts.

Use switch option to print out.(cout) the following

Day of week number of part,and cost of part (each part cost 1.55)

For example , if two number are 545, then print out

     Friday 45 69.75

Your program should read oneline (two integer) at a time and print out all information asrequired above, until the end of file

b)      Find the average(in float) of 16fib number in sequence, with first number entered by the user (thiscondition must be met) for example, if the user enter 5 then thesequence is from fib(5) to fib(20).

You r program uses a for loop for(b).

c)         read from inputfile (test2.txt)two integers at time. These two numbers are in asingle line. Call GCD function to out put the GCD return oneinteger. Print out (cout)these two number and their GCD. Forexample, if two number are 5 45 then print out 5 45 5. Read fromline one till end of file each read in line. (two number) shouldhave its corresponding print-out(cout).

Your program should also calculateand print out the average (in float) of all GCD’s your

Program uses a while loop for (C)

Explanation / Answer

#include <iostream.h>

#include <fstream.h>

#include <iomanip.h>

int main()

{int day,part;

double cost,single=1.55;

ifstream in;

in.open("test1.txt"); //open file

if(in.fail()) //is it ok?

{ cout<<"input file did not open please checkit ";

system("pause");

return 1;

}

cout<<fixed<<showpoint;

cout<<setprecision(2);

in>>day;

while(in)

{in>>part;

cost=part*single;

switch(day)

{

case 1: cout<<"Monday "<<part<<""<<cost<<endl;

break;

case 2: cout<<"Tuesday "<<part<<""<<cost<<endl;

break;

case 3: cout<<"Wednesday "<<part<<""<<cost<<endl;

break;

case 4: cout<<"Thursday "<<part<<""<<cost<<endl;

break;

case 5: cout<<"Friday "<<part<<""<<cost<<endl;

break;

default: cout<<"Illegal day in file ";

break;

}

in>>day;

}

in.close();

system("pause");

return 0;

}