0% found this document useful (0 votes)
2 views8 pages

Introduction To Computing@assignment Latest

This document outlines the assignment requirements for an Introduction to Computing course at Jimma University, including submission guidelines and question distributions for programming tasks. It provides detailed instructions for submitting source code, including naming conventions and file formats, as well as a list of programming questions covering various topics such as taxi fare calculation, approximating PI, and weather statistics. Each question includes specific programming tasks and input validation requirements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Introduction To Computing@assignment Latest

This document outlines the assignment requirements for an Introduction to Computing course at Jimma University, including submission guidelines and question distributions for programming tasks. It provides detailed instructions for submitting source code, including naming conventions and file formats, as well as a list of programming questions covering various topics such as taxi fare calculation, approximating PI, and weather statistics. Each question includes specific programming tasks and input validation requirements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JIMMA UNIVERSITY

JIMMA INSTITUTE OF TECHNOLGY


SCHOOL OF BIOMEDICAL
INTRODUCTION TO COMPUTING ASSIGNMENT
SUBMISSION DATA: FRIDAY, JANUARY 25, 2019
TOTAL MARKS: 20 PTS
Instructions:
1. STRICTLY FOLLOW THE INSTRUCTIONS THAT FOLLOWS
2. Late submission is not acceptable
3. Save your source codes using appropriate file name (Tip: use
the question # & problem title (if given).

E.g. If a programming problem given to you has a title


‘Customer PIN Validation’ & its question number is Q1, then
Q1_Customer_PIN_Validation would be an ideal file name.

4. Send your source codes in Zip-File format, and give


appropriate file name.

E.g., if you belongs to peer-group 2 and section-2, name


your folder (the container for your source codes) as
SEC2_PG2

- Right click on ‘SEC2_PG2’ and click ‘Add to archive’,


this will create Zip-file ( SEC2_PG2.rar)

5. If N number of groups submit exactly the same source code to


any of the question , the group mark will be reduced by a
1
factor of , i.e., each group will get reduced mark as
N
indicated below:

Question distribution
Section/Group-I Section/Group-II
Question # Peer group # Question # Peer group #
4,6,5,7 1 5,7,9,10 1
5,7,8,10 2 2,5,7,10 2
1,3,5,7 3 3,5,7,9 3
2,5,7,8 4 4,5,7,10 4
3,5,6,7 5 5,6,7,9 5
1,4,5,7 6 1,5,7,9 6
1,5,7,8 7 4,5,7,9 7
3,5,7,4 8 1,5,7,8 8
2,5,7,9 9 3,4,5,7 9
3,5,7,8 10 1,5,6,7 10
2,5,7,6 11 2,5,7,8 11
Question # 1: Taxi Fare
A taxicab company calculates charges using a fixed $3.20 hire charge, a $2.05-per-kilometer
charge for the distance covered, and an additional $0.95-per-minute charge based on the duration
of the journey, in minutes. If the journey starts between 2300 and 0600
hours, a 15% surcharge is applied.

Write a program that asks the user to input the duration of the journey (rounded up to the nearest
minute), the distance traveled (in kilometers, and the journey start time (as a 24-hour single
int value). The program should then output the fare that should be charged.

Question # 2: Approximate PI
An approximate value of pi can be calculated using the series given below:

n
PI =4 [1−1/3+1/5−1/7 +1/9 …+ (−1 ) /(2 n+1)]

Write a C++ program to calculate the approximate value of pi using this


series. The program takes an input n that determines the number of terms
in the approximation of the value of pi and outputs the approximation.
Include a loop that allows the user to repeat this calculation for new
values n until the user says she or he wants to end the program.

Question # 3: Lo Shu Magic Square

The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in Figure 7-19.
The Lo Shu Magic Square has the following properties:
• The grid contains the numbers 1 through 9 exactly.
• The sum of each row, each column, and each diagonal all add up to the same
number. This is shown in Figure below.

In a program you can simulate a magic square using a two-dimensional array. Write
a
function that accepts a two-dimensional array as an argument, and determines
whether
the array is a Lo Shu Magic Square. Test the function in a program.

Question # 4 Soccer Scores

Write a program that stores the following data about a soccer player in a structure:
Player’s Name
Player’s Number
Points Scored by Player
The program should keep an array of 12 of these structures. Each element is for a different player
on a team. When the program runs it should ask the user to enter the data
for each player. It should then show a table that lists each player’s number, name, and
points scored. The program should also calculate and display the total points earned by
the team. The number and name of the player who has earned the most points should
also be displayed.
Input Validation: Do not accept negative values for players’ numbers or points scored.

Question # 5 Calories calculator


To maintain one’s body weight, an adult human needs to consume enough
calories daily to (1) meet the basal metabolic rate (energy required to
breathe, maintain body temperature, etc.), (2) account for physical activity
such as exercise, and (3) account for the energy required to digest the food
that is being eaten. For an adult that weighs P pounds, we can estimate
these caloric requirements using the following formulas:

A. Basal metabolic rate: Calories required=70 ∙ ( P/2.2 )0.756


B. Physical activity: Calories required=0.0385∗Intensity∗P∗Minutes

Here, Minutes is the number of minutes spend during the physical activity, and Intensity is a
number that estimates the intensity of the activity. Here are some sample numbers for the range
of values:
Activity Intensity
Running 10 mph: 17
Running 6 mph: 10
Basketball: 8
Walking 1 mph: 1
C. Energy to digest food: calories required=TotalCaloriesConsumed∗0.1
In other words, 10 percent of the calories we consume goes towards digestion.

Write a function that computes the calories required for the basal metabolic rate, taking as input
a parameter for the person’s weight. Write another function that computes the calories required
for physical activity, taking as input parameters for the intensity, weight, and minutes spent
exercising.

Use these functions in a program that inputs a person’s weight, an estimate for the intensity of
physical activity, the number of minutes spent performing the physical activity, and the number
of calories in one serving of your favorite food. The program should then calculate and output
how many servings of that food should be eaten per day to maintain the person’s current weight
at the specified activity level. The computation should include the energy that is required to
digest food.

You can find estimates of the caloric content of many foods on the Web. For example, a double
cheeseburger has approximately 1000 calories. (Use this website to estimate caloric content of
your favorite food: [Link] )

Remark: While selecting your favorite food make sure it exist in the website given above (as the
caloric content for most Ethiopian foods are unavailable on website). If you can’t find your
favorite food use DOUBLE CHEESE BURGER as your # 1 choice.

Question # 6: Weather Statistics

Write a program that uses a structure to store the following weather data for a particular month:
Total Rainfall
High Temperature
Low Temperature
Average Temperature
The program should have an array of 12 structures to hold weather data for an
entire year. When the program runs, it should ask the user to enter data for each
month. (The average temperature should be calculated.) Once the data are entered
for all the months, the program should calculate and display the average monthly
rainfall, the total rainfall for the year, the highest and lowest temperatures for the
year (and the months they occurred in), and the average of all the monthly average
temperatures.
Input Validation: Only accept temperatures within the range between –100 and +140
degrees Fahrenheit.

Question # 7: Course Grade

Write a program that uses a structure to store the following data:

Member Name Description


Name Student name
Idnum Student ID number
Tests Pointer to an array of test scores
Average Average test score
Grade Course grade

The program should keep a list of test scores for a group of students. It should ask the
user how many test scores there are to be and how many students there are. It should
then dynamically allocate an array of structures. Each structure’s Tests member
should point to a dynamically allocated array that will hold the test scores.
After the arrays have been dynamically allocated, the program should ask for the ID
number and all the test scores for each student. The average test score should be calculated and
stored in the average member of each structure. The course grade should
be computed on the basis of the following grading scale:
Average Test Grade Course Grade
91-100 A
81-90 B
71-80 C
61-70 D
60 or below F

The course grade should then be stored in the Grade member of each structure. Once
all this data is calculated, a table should be displayed on the screen listing each student’s
name, ID number, average test score, and course grade.
Input Validation: Be sure all the data for each student is entered. Do not accept negative
numbers for any test score.

Question # 8: Drink Machine simulator

Write a program that simulates a soft drink machine. The program should use a structure
that stores the following data:

Drink Name
Drink Cost
Number of Drinks in Machine
The program should create an array of five structures. The elements should be initialized
with the following data:

Drink Name Cost ($) Number in Machine


Cola .75 20
Root Beer .75 20
Lemon-Lime .75 20
Grape Soda .80 20
Cream Soda .80 20

Each time the program runs, it should enter a loop that performs the following steps:
A list of drinks is displayed on the screen. The user should be allowed to either quit the
program or pick a drink. If the user selects a drink, he or she will next enter the amount
of money that is to be inserted into the drink machine. The program should display
the amount of change that would be returned and subtract one from the number of
that drink left in the machine. If the user selects a drink that has sold out, a message
should be displayed. The loop then repeats. When the user chooses to quit the program
it should display the total amount of money the machine earned.
Input Validation: When the user enters an amount of money, do not accept negative
values or values greater than $1.00.
Question # 9: Payroll
Write a program that uses the following arrays:
• empId: an array of seven long integers to hold employee identification numbers. The
array should be initialized with the following numbers:
5658845 4520125 7895122 8777541
8451277 1302850 7580489
• hours: an array of seven integers to hold the number of hours worked by each
employee
• payRate: an array of seven doubles to hold each employee’s hourly pay rate
• wages: an array of seven doubles to hold each employee’s gross wages
The program should relate the data in each array through the subscripts. For example,
the number in element 0 of the hours array should be the number of hours worked by the
employee whose identification number is stored in element 0 of the empId array. That same
employee’s pay rate should be stored in element 0 of the payRate array.

The program should display each employee number and ask the user to enter that
employee’s hours and pay rate. It should then calculate the gross wages for that
employee (hours times pay rate) and store them in the wages array. After the data has
been entered for all the employees, the program should display each employee’s identification
number and gross wages.

Input Validation: Do not accept negative values for hours or numbers less than 15.00
for pay rate.

Question # 10:
The value e x can be approximated by the sum

Write a program that takes a value x as input and outputs this sum for n taken
to be each of the values 1 to 100. The program should also output e x calculated
using the predefined function exp. The function exp is a predefined function
such that exp(x) returns an approximation to the value ex. The function exp
is in the library with the header file cmath. Your program should repeat the
calculation for new values of x until the user says she or he is through.
Use variables of type double to store the factorials or you are likely to
produce integer overflow (or arrange your calculation to avoid any direct
calculation of factorials). 100 lines of output might not fit comfortably
on your screen. Output the 100 output values in a format that will fit all
100 values on the screen. For example, you might output 10 lines with
10 values on each line.

You might also like