Uploaded by m9.3b

computer programming projects

advertisement
College of Engineering & Information Technology
Department of Electrical & Computer Engineering
2131400 Computer Programming
1) Write a C++ program that reads a list of double-precision grades from the keyboard into
an array named grade. The grades are to be counted as they're read, and entry is to be
terminated when a negative value has been entered. After all grades have been input, your
program should find and display the sum and average of the grades. The grades should
then be listed with an asterisk (*) placed in front of each grade that's below the average.
Extend the program to display each grade and its letter equivalent, using the following
scale:
Between 90 and 100 = A
Greater than or equal to 80 and less than 90 = B
Greater than or equal to 70 and less than 80 = C
Greater than or equal to 60 and less than 70 = D
Less than 60 = F
2) Write a C++ program that determines grades at the end of the semester. For each student,
identified by an integer number between 1 and 60, four exam grades must be kept, and
two final grade averages must be computed. The first-grade average is simply the average
of all four grades. The second-grade average is computed by weighting the four grades as
follows: The first grade gets a weight of 0.2, the second grade gets a weight of 0.3, the
third grade gets a weight of 0.3, and the fourth grade gets a weight of 0.2. That is, the final
grade is computed as follows:
0.2 * grade1 + 0.3 * grade2 + 0.3 * grade3 + 0.2 * grade4
Using this information, construct a 60-by-7 two-dimensional array, in which the first
column is used for the student number; the next four columns for the grades, and the last
two columns for the computed final grades. The program's output should be a display of
the data in the completed array. For testing purposes, use the following data:
Prepared by Eng.Musaab Hasan
3) A clever and simple method of preparing to sort dates into ascending (increasing) or
descending (decreasing) order is to convert a date in the form month/day/year into an
integer number with the formula date= year x 10000 +month x 100 +day. For example,
using this formula, the date 12/6/1988 converts to the integer 19881206, and the date
2/28/2014 converts to the integer 20140228. Sorting the resulting integer numbers puts
dates into the correct order automatically. Using this formula, write a function named
convertdays () that accepts a month, day, and year; converts the passed data into a single
date integer; and returns the integer to the calling function. Include the convertdays ( )
function in a working program. The main ( ) function should call convertdays () multiple
times for five dates and to get the integer the function returns then order and display the
five dates in order in the format of 12/6/1988.
4) Write and test a C++ function named makeMilesKmTable ( ) to display a table of miles
converted to kilometers. The arguments to the function should be the starting and
stopping values of miles and the increment. The output should be a table of miles and their
equivalent kilometer values. Use the relationship that 1 mile = 1.61 kilometers. The
function must display two columns. For example, if the starting value is 1 mile, the ending
value is 20 miles, and the increment is 1, the display should look like the following:
Miles = Kilometers
1
1.61
2
3.22
.
.
10
16.09
Miles = Kilometers
11
17.70
12
19.31
.
.
20
32.18
5) Euclid's method for finding the greatest common divisor (GCD) of two positive integers
consists of the following steps:
Step 1: Divide the larger number by the smaller and retain the remainder.
Step 2: Divide the smaller number by the remainder, again retaining the remainder.
Step 3: Continue dividing the previous remainder by the current remainder until the
remainder is zero. at which point the last non-zero remainder is the GCD.
Prepared by Eng.Musaab Hasan
For example. if the two positive integers are 84 and 49, you have the following:
Step 1: 84/49 yields a remainder of 35.
Step 2: 49/35 yields a remainder of 14.
Step 3: 35/14 yields a remainder of 7.
Step 3: 14/7 yields a remainder of 0.
Therefore, the last non-zero remainder, which is 7, is the GCD of 84 and 49. Using Euclid's
algorithm, write an actual function that determines and returns the GCD of its two integer
arguments.
Prepared by Eng.Musaab Hasan
Download