Question: Name: ______________________________________ Student #: _____________________________________ we're using C++. Thank you SODV 1101 Programming Fundamentals Term Year Assignment 01 Instructor: Instructor Name Due Date: YYYY-MM-DD Directions:
Name: ______________________________________ Student #: _____________________________________ we're using C++. Thank you SODV 1101 Programming Fundamentals Term Year Assignment 01 Directions: #include #include #include using namespace std; Note: The assignment's written questions not submitted as a single file will not be graded!
Instructor: Instructor Name Due Date: YYYY-MM-DD
Written Questions 1 / 5 2 / 5 3 / 5 4 / 5 5 / 5 6 / 5 Programming Questions Quality / 20 Functionality / 50 Total / 100
Assignment 1: Written Questions
| 1. | Give concise answers to the following questions | / 5 | |
| a) | What is a compiler?
| / 1 | |
| b) | What is pseudocode?
| / 1 | |
| c) | What is the difference between an expression and a statement?
| / 3 | |
| 2. | Give concise answers to the following questions | / 5 | |
| a) | Illustrate the differences between syntax errors and logical errors with examples
| / 2 | |
| b) | What will the function call q2(5, 5, 2) return?
| / 3 |
| 3. Identify all the errors (syntax error and logical error) in the following program implementation Mark the errors in the code below with a circled number corresponding to the spaces provided, briefly explain why it is an error,and give a fix for it.
1) Syntax Error: ___________________________________________________ ___________________________________________________
2) Syntax Error: ___________________________________________________
___________________________________________________
3) Syntax Error: ___________________________________________________
___________________________________________________
4) Syntax Error: ___________________________________________________
___________________________________________________
5) Logic Error: ___________________________________________________
___________________________________________________ /5
|
| 4. | Give concise answers to the following questions | / 5 | |
| a) | Write truth tables for the logical AND, OR, and NOT operators.
| / 3 | |
| b) | What do you mean by a breakpoint?
| / 2 | |
| 5. | / 5 | ||
| a) | What would be the output of the following code? And why?
int main() { int x = 2; switch (x) { case 1: cout<<"Choice is 1"; break; case 2: cout<<"Choice is 2"; case 3: cout<<"Choice is 3"; break; default: cout<<"Choice other than 1, 2 and 3"; break; } return 0; }
| / 2.5 | |
| b) | What will the function call q2b('R', 5, false); return from the following code?
| / 2.5 |
| 6. In the following function implementation, there are4 syntax errors and 1 type of logical error[same error type can be there in one or more lines]. Mark the errors in the code below with a circled number corresponding to the spaces provided. Briefly explain why it is an error andgive a fix for it.
1) Syntax Error: ___________________________________________________ ___________________________________________________
2) Syntax Error: ___________________________________________________
___________________________________________________
3) Syntax Error: ___________________________________________________
___________________________________________________
4) Syntax Error: ___________________________________________________
___________________________________________________
5) Logic Error: ___________________________________________________
___________________________________________________
| / 5 |
Program A: BMI Calculator
Learning Objective
- Identify program structure and control the flow of execution.
- Define variables and use them to store data.
- Write structured programming instruction so that the computer shows input/output behaviors
- Use operators to perform calculations.
- Employ data store elements in program implementation.
- Demonstrate logical thinking by using programming syntax and strategies.
Overview
Write a program to calculate the user's body mass index (BMI).
Directions
A person's body mass index (BMI) is calculated using height and weight. The formula for BMI is:
BMI = kg / m2
Where kg is the person's mass in kilograms, and m2 is their height in meters squared.
Write a program to calculate a person's BMI. Your program should first ask the user to enter their height in feet and inches, then their weight in pounds. Your program should then use the data to calculate the person's BMI. Your program should also display the person's height and weight in meters and kilograms. There are 12 inches in a foot, 3.28084 feet in a meter, and 2.20462 pounds in a kilogram.
The listing below shows an example of what the input and output for this program might look like. Input by the user is listed inblue.
| Sample Input/Output:
What is your height? Feets:5 Inches:10 What is your weight (lbs)?160
Height (m): 1.78 Weight (kg): 72.57 BMI: 22.96 |
Program B: Restaurant Bill
Learning Objective
- Identify program structure and control the flow of execution.
- Define variables and use them to store data.
- Write structured programming instruction so that the computer shows input/output behaviors
- Use operators to perform calculations.
- Describe operator precedence and expressions.
- Employ data store elements in program implementation.
- Demonstrate logical thinking by using programming syntax and strategies.
Overview
Write a program to split a restaurant bill evenly between a given number of people.
Directions
Write a program for calculating and splitting restaurant bills. Your program should ask the user how much the bill is before applying tax, what percentage the sales tax is, what percentage tip they would like to add, and how many people are splitting the bill. Calculate the final cost of the bill by first adding the sales tax, then adding the tip. Find the cost per person by dividing the bill by the number provided. Print each value to the console: the bill before tax, the bill after tax, the bill after tip, and the bill per person.
The listing below shows an example of what the input and output for this program might look like. Input by the user is listed inblue.
| Sample Input/Output:
How much is the bill?57.75 How much is the tax (%)?5 How much is the tip (%)?20 How many people are paying?3
Bill before tax: 57.75 Bill after tax: 60.64 Bill after tip: 72.76 Bill per person: 24.26 |
Program C: Monthly Telephone Bill
Learning Objective
- Identify program structure and control the flow of execution.
- Define variables and use them to store data.
- Write structured programming instruction so that the computer shows input/output behaviors
- Use operators to perform calculations.
- Describe operator precedence and expressions.
- Employ data store elements in program implementation.
- Create basic functions to reuse code.
- Demonstrate logical thinking by using programming syntax and strategies.
Overview
Write a program to calculate the monthly telephone bills as per the following rule:
Directions
You must accept the total number of calls from the user and calculate the monthly (pay as you go) bill according to the following rule.
Minimum $20 for up to the first 100 calls. Plus $0.30 per call for the next 50 calls. Plus $0.20 per call for the next 50 calls. Plus $0.10 per call for any call beyond 200 calls.
Sample Input/Output 01:
Enter the total number of calls: 130
Your Monthly bill is: $29
Sample Input/Output 02:
Enter the total number of calls: 180
Your Monthly bill is: $41
Sample Input/Output 03:
Enter the total number of calls: 500
Your Monthly bill is: $75
Evaluation
This assignment has 2 main components, assigned marks as follows:
| Task | Marks |
| Written Questions | 30 |
| Code Quality and Functionality | 70 |
| Total | 100 |
Marks for written questions are indicated beside each question.
Thefollowing rubrics will be followed for assessing the program code:
| Excellent (100%) | Competent (80%) | Satisfactory (50%) | Unsatisfactory (0%) |
|
|
|
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
