Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Bahria University computer programming assignment
1. Bahria University
Lahore Campus
Department of Computer Science
Computer Programming (CSC-113)
Assignment 01 (There will be a test in the start of lecture on 21OCT-19)
Max Marks: 50 Deadline: 18-Oct-19 (Friday) 3pm
Question # 1 [4 marks]
Write down the E notation for each of the following expressions in the given manner?
Expression E-Notation
A) 3.287 × 106
B) -978.65 × 1012
C) 7.65491 × 10-3
D) -58710.23 × 10-4
Question # 2 [6 marks]
Distance per Tank of Gas
A car with a 20-gallon gas tank averages 21.5 miles per gallon when driven in town and 26.8 miles
per gallon when driven on the highway. Write a program that calculates and displays the distance
the car can travel on one tank of gas when driven in town and when driven on the highway.
Hint: The following formula can be used to calculate the distance:
Distance = Number of Gallons × Average Miles per Gallon
Question # 3 [4+6 marks]
(A) Type the above code and note down the output of your program.
(B) Do the same work using const variables of appropriate data type, instead of #define.
#include <iostream>
using namespace std;
#define WHO "Columbus"
#define DID "sailed"
#define WHAT "the ocean blue."
int main()
{
const int WHEN = 1492;
cout << "In " << WHEN << " " << WHO << " "
<< DID << " " << WHAT << endl;
return 0;
}
2. Question # 4 [10 marks]
Note down (in your own handwriting) the C++ Library function that returns each of the following:
01. The cosine of an angle. 02. The sine of an angle.
03. The tangent of an angle. 04. The exponential function of a number.
05. The remainder of a floating point division. 06. The natural logarithm of a number.
07. The base-10 logarithm of a number. 08. The value of a number raised to a power.
09. The square root of a number.
Also note down the header file that is required to be included for above functions.
Question # 5 [10 marks]
Pizza Pi
Joe’s Pizza Palace needs a program to calculate the number of slices a pizza of any size can be
divided into. The program should perform the following steps:
A) Ask the user for the diameter of the pizza in inches.
B) Calculate the number of slices that may be taken from a pizza of that size.
C) Display a message telling the number of slices.
To calculate the number of slices that may be taken from the pizza, use the following facts:
• Each slice should have an area of 14.125 inches.
• To calculate the number of slices, simply divide the area of the pizza by 14.125.
• The area of the pizza is calculated with this formula:
NOTE: Area = πr2. π is the Greek letter pi. 3.14159 can be used as its value. The variable r is the
radius of the pizza. Divide the diameter by 2 to get the radius. Use a named constant for pi.
Question # 6 [10 marks]
Word Game
Write a program that plays a word game with the user. The program should ask the user to enter
the following:
• His or her name
• His or her age
• The name of a city
• The name of a college
• A profession
• A type of animal
• A pet’s name
After the user has entered these items, the program should display the following story, inserting
the user’s input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of AGE, NAME went to
college at COLLEGE. NAME graduated and went to work as a PROFESSION. Then, NAME
adopted a(n) ANIMAL named PETNAME. They both lived happily ever after!
Submit handwritten solution of this assignment before the deadline given in the title.