You are on page 1of 11

National University of Sciences and Technology (NUST)

SMME

LAB REPORT
LAB REPORT # 4

COURSE : Fundamentals of Programming

SUBMITTED BY : Altaf Ahmad (250282)

SUBMITTED TO: Ahmad Subhani

SECTION : ME-10 A

DATE : October 18, 2018


Program#1: Write and Execute Compute the new velocity and acceleration
of the aircraft after a change in power level:
1: Enter different values of time until you find one that gives a velocity between 210 m/s
and 211 m/s.
2: Enter different values of time until you find one that gives an acceleration between
0.5 m/s and 0.6 m/s.
3: Modify the program so that the input values are entered in minutes instead of
seconds. Remember that the equations will still assume that the time values are in
seconds.
4: Modify the program so that the output values are printed in feet per second, and feet
per second2. (Recall that 1 meter = 39.37 inches.).

(Part 1 and Part 2):


Code:

Description:
This program calculates the velocity and acceleration for different values of time.
The time changes the velocity and acceleration according to the formulas written in the
program. The part 1 is to find the appropriate time at which the velocity is found to be a
value between 210 m/s and 211 m/s. The part 2 is to find the appropriate time at which the
acceleration gives a value between 0.5 m/s2 and 0.6 m/s2.
Explanation:
After loading the preprocessor directives and the standard libraries, the program
declares three objects as doubles and names them time, velocity and acceleration. Then the
user is asked to enter a value of time with the help of keyboard. Using the formulas, the
velocity is calculated and similarly, acceleration as well. The function pow(x,y) can be used
because the preprocessor directive <cmath> was included at the top of the program. And
then finally the values of velocity and acceleration are printed on screen with a precision of
four decimal digits after the decimal point. And the width of velocity is set to 10 while
acceleration to 14. And so the final output values of the velocity and acceleration are
calculated with the help of time given by the user and printed with their respective units.
Output: (Solution)
1: By putting different values of time, it is found that the value of time 58 seconds gives the
appropriate value for the part 1 as the velocity is found to be 210.852 which is a value
between 210 and 211.

2: Similarly, for the part 2, different values of time are tested and finally the time value of 25
satisfies the requirements as the acceleration is found to be 0.584 which is a value between
0.5 and 0.6.

Explanation:
In the output, at first the program asks the users to enter the desired value of time.
Using that value of time, the values of velocity and acceleration are printed with their
respective units.
Flowchart:
(Part 3):
Code:

Description:
The program works like before but is modified to take time in minutes instead of
seconds.
Explanation:
The program is just like before but takes time in minutes which are then converted
to seconds again for the equations. The rest of the program works just like it did in part 1
and part 2.
Output:

Explanation:
The program now takes the time in minutes. And so, the velocity and acceleration
become very large because 58 minutes are relatively a much longer time than 58 seconds.
Flowchart:

(Part 4):
Code:

Description:
The program is modified to calculate velocity and acceleration in feet per second and
feet per second.
Explanation:
The program works like it did in part 1 but velocity and acceleration are multiplied by 3.28 to
convert meter into feet (1 meter = 3.28 feet). So, the velocity and acceleration are calculated in ft/s
and ft/s2 instead of m/s and m/s2.
Output:

Explanation:
The program takes the time from the user in seconds. And then the velocities and
acceleration are calculated and printed on screen in respective units (ft/s and ft/s2)
TASK # 2
Program # 1: Write a program to computer and print the molecular weight of glycine.
Code:

Description:
The program written above basically calculates the molecular weight of glycine by
using weights and no. of atoms of different elements involved in the molecular of glycine.
Explanation:
After loading the preprocessor directives and standard libraries, different variables
named after the atoms with their atomic weight assigned to them are defined. The variables
are oxygen = 15.9994, carbon = 12.011, nitrogen = 14.00674, sulfur = 32.066, hydrogen =
1.00794. All the variables are defined as doubles because they consist of floating point
decimal numbers. Another double type variable named glycine is declared and the atomic
weight of glycine is assigned to it by using the molecular formula of glycine. And finally, the
molecular weight of glycine is printed. And then the program exits.
Output:

Explanation:
The program output simply shows the molecular weight of glycine which is 75.0672.
This is calculated by the program. And since the molecular weight of glycine is actually 75.07
so we know that our program is running accurately.
Flowchart:

Program # 2: Write a program to computer and print the molecular weights of glutamic
acid and glutamine.
Code:

Description:
The program written above basically calculates the molecular weight of glutamic acid
and glutamine by using weights and no. of atoms of different elements involved in the
molecular of glutamic acid and glutamine.
Explanation:
After loading the preprocessor directives and standard libraries, different variables
named after the atoms with their atomic weight assigned to them are defined. The variables
are oxygen = 15.9994, carbon = 12.011, nitrogen = 14.00674, sulfur = 32.066, hydrogen =
1.00794. All the variables are defined as doubles because they consist of floating point
decimal numbers. Other double type variables named glutamic and glutamine are declared
and the atomic weight of glutamic acid and glutamine are assigned to them respectively by
using the molecular formula of glycine. And finally, the molecular weight of glutamic acid
and glutamine are printed. And then the program exits.
Output:

Explanation:
In the output, the molecular weights of glutamic acid and glutamine are shown on
the screen. The molecular weight of glutamic acid is 147.131 and that of glutamine is
146.46. Comparing it to the real values, we determine the accuracy of our program.
Flowchart:
Program # 3: Write a program that asks the user to enter the number of atoms of each
of the five elements for an amino acid. Then compute and print the molecular weight for
this amino acid.
Code:

Description:
The program written above basically calculates the molecular weight of an amino
acid by using weights and no. of atoms of different elements involved in the molecular of
glutamic acid and glutamine.
Explanation:
After loading the preprocessor directives and standard libraries, different variables
named after the atoms with their atomic weight assigned to them are defined. The variables
are oxygen = 15.9994, carbon = 12.011, nitrogen = 14.00674, sulfur = 32.066, hydrogen =
1.00794. All the variables are defined as doubles because they consist of floating point
decimal numbers. Five other int type variables named o,c,n,s and h are declared. Then the
user is asked to enter the number of atoms of each of the five elements one by one and
they are stored in o,c,n,s and h respectively. Finally a double variable named amino acid is
defined which stores the calculated value of molecular weight of the amino acid using
weight and number of atoms of the elements. Finally, the molecular weight of the amino
acid is printed on the screen. And then the program exits.
Output:
Explanation:
In the output, the program asks the user to enter number of oxygen atoms, carbon
atoms, nitrogen atoms, sulfur atoms and hydrogen atoms. And finally, the program
calculates the molecular weight of the amino acid and gives the calculated value.
Flowchart:

You might also like