Programming Problems-Gas Mileage Calculator - Pascal programming

  1. Gas

    Create an algorithm that inputs sequences of two values Miles and Gals representing the mileage and gallons of gasoline at a succession of refills. The algorithm is to compute and output the immediate average miles-per-gallon (labeled Short for short range), and also the overall average mpg (since the beginning of the data), which is labeled Long for long range. A typical input-output sequence follows (and should end with negative mileage).

    Miles Gals Short Long 1000 20 1200 10 20 20 1500 20 15 16.67 ... ... ... ...
  2. GPA

    The grade point average of a student is computed from all the course grades G and units U. Corresponding to each grade is a numeric point P (where A has 4 points, B has 3 points, etc.). The products of each grade point and its number of units are then summed. This sum is divided by the total number of units, to yield the grade point average. Create an algorithm to compute the grade point average for a sequence of pairs of values G, U (ending with negative values).

  3. Speed

    Create an algorithm to analyze the speed during a trip of N stops. At each stop, the distance D and time T from the previous stop are recorded. These pairs of values are then input to a program which computes each velocity (V = D/T) and outputs it. It also ultimately indicates the maximum speed on the trip, and the overall average (total distance divided by total time).

    SAMPLE RUN (N = 5)
    D T V 45 1 45 100 2 50 55 1 55 120 2 60 Avg = 380/8 = 47.5 60 2 30 Max = 60
  4. Unbiased Mean

    In some sports, a number of judges each ranks performance on a scale from 1 to 10. To adjust for biases, both the highest and lowest values are eliminated before computing the average. Create an algorithm to compute such an average for M judges on N performances.

  5. More Plots

    Modify the program SidePlotXY of this Chapter as follows:

    a. Mark points on the axes.
    b. Plot a third function.
    c. Input the size of the grid.
  6. Upright Plots

    Create an “upright” plot program, similar to the SidePlotXY program in this. Modify it as shown above.

  7. Calendar

    Create a program to print out a calendar for a month, given the number of days in the month and the starting day of the week. Create a grid of horizontal lines and vertical lines.

  8. Encrypt-Decrypt

    Create a program to input a file of characters, to encrypt it for security purposes in such a way that it is not easily understandable and to output it to another file. Then create another program that reconverts the encrypted file and returns the original file. Your algorithm could a simple arithmetic function on the ASCII values or use a random number generator.

  9. Flasher2

    Modify the Flasher program of this chapter to keep track of the number of correct answers.

  10. Binconvert

    Create an algorithm to convert a sequence of binary input characters (not integers) into their corresponding decimal values. For example, 1101 is the decimal 13

    1. Write the algorithm, if the input is read from left to right (ending with a period).
    2. Write the algorithm, if the input is read from right to left (ending with a blank).
  11. When in Rome...

    One method for converting an Arabic number into a Roman number is to separately convert each digit (the units, tens, hundreds, and thousands positions) as shown.

    1 9 8 4
  12. Write an algorithm that accepts as inputs any values up to 3999, and outputs the corresponding Roman numbers.

    1. Do this, if the number is entered digit by digit (least significant digits first, like 4 8 9 1).
    2. Do this, if the number is entered digit by digit (most significant digits first, like 1 9 8 4).
    3. Do this, if the number is entered as an integer, like 1984.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Pascal programming Topics