Starting from:

$30

Computer Programming HW 01 Solution




(35 Pts) Write a complete C program which evaluates the fog(x) and gof(x) using the following functions for some user defined integer x (y is defined as a constant macro).









 x  y






2.5


1


 log(
3x
g ( x )  x 






f (x)  sin 




) 


y














x 



x




2 x1



2x




















Write the program using (at least) the functions below:




double gx ( …. ) : takes x and y and returns value for f(x).



double fx ( …. ) : takes x and y and returns value for g(x).



Variables x will be supplied by an input text file named ‘Variables.txt’. The input file will consist only the integer variables (no other text) separated by white space characters. The result will both be printed on the console and saved to an output text file named ‘Results1.txt’. The console output should include a meaningful explanation but the file should include a numeric value only.




You may need to use some mathematical identities to implement some mathematical functions not directly supported by ‘math.h’ library.







(30 Pts)Write a complete C program which finds x and y using the following linear equations with two unknowns and calculates f (x,y). The coefficients will be supplied by a text file named as ‘EqCoefficients.txt’ for equations and ‘FuncCoefficients.txt’ for f (x,y).



Equation1  0.3 x  0.4 y  2000

f ( x, y )  30 x  35y

Equation 2   0.4 x  0.2 y 1500







The format of the input file ‘EqCoefficients.txt’ will be as follows:




coefficient of x for 1st eq. < coefficient of y for 1st eq.< result of 1st equation
coefficient of x for 2st eq. < coefficient of y for 2st eq.< result of 2st equation



The format of the input file ‘FuncCoefficients.txt’ will be as follows:




< coefficient of x for function < coefficient of y for function

The results (x, y and f(x,y)) will both be printed on the console and saved to an output text file named ‘Results2.txt’. The console output should include a meaningful explanation but the file should include a numeric value only.




An example of inputs and outputs are shown below:




Content of ‘EqCoefficients.txt’:

0.3 0.4 2000

0.4 0.2 1500




Content of ‘FuncCoefficients.txt’:

30 35




Content of ‘Results2.txt’:

2000 3500 182500







(35 Pts) Write a complete C program which reads car information from an input text file named as ‘Cars.txt’ and output total fuel cost. The input file will include the information of 3 cars. The information of each purchase will be in a separate line as shown below.



<Car1 <amount (lt) of fuel consumed per km <price of fuel (1lt) <total km taken by car1 <Car2 <amount (lt) of fuel consumed per km <price of fuel (1lt) <total km taken by car2 <Car3 <amount (lt) of fuel consumed per km <price of fuel (1lt) <total km taken by car3




Item codes for cars are represented by integers, others are represented by floating point numbers.




The output will both be printed on the console and saved to a text file named ‘TotalFuelCosts.txt’. In the console output total fuel costs should be displayed as TL and Kurus format, but in the file total fuel cost should be represented by 2 precision floating point numbers. The console output should include a meaningful explanation but the file should include item codes and total fuel costs separated by white space characters only. The format of the output file is shown below:







An example of inputs and outputs are shown below:






Content of ‘Cars.txt’:
1
1.2
4.36
150
2
2.0
2.24
80
3
0.8
1.69
230



Content of ‘TotalFuelCosts.txt’:

784.50
358.40
310.96



Console Output:

The total fuel cost of the car 1 is 784 TL and 50 Kurus.






General:

Obey honor code principles.



Read your homework carefully and follow the directives about the I/O format (data file names, file formats, etc.) and submission format strictly. Violating any of these directives will be penalized.



Obey coding convention.



Your submission should include the following files and NOTHING MORE (no data files, object files, etc):



HW01_<student_name_<studentSirname_<student number_part1.c HW01_<student_name_<studentSirname_<student number_part2.c HW01_<student_name_<studentSirname_<student number_part3.c

Do not use non-English characters in any part of your homework (in body, file name, etc.).
Deliver the printout of your work until the last submission date.

More products