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

Instructor: Instructor Name Due Date: YYYY-MM-DD

Directions:

  • Written questions must be submitted as a single DOCX or PDF format to the d2l dropbox,as a single doc file or single pdf file. Answers should be written clearly and coherently.One CPP file must be submitted for each programming question.
  • Assignments must be submitted by the posted due date, or be subject to the course's late policy. Work must be completed individually and in accordance with the academic integrity policy.
  • All codes shown in this assignment are compiled and tested except for questions that aim to find errors in a C++ program.
  • For all written questions, you may assume that the usual header files are included as follows:

#include

#include

#include

using namespace std;

Note: The assignment's written questions not submitted as a single file will not be graded!

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?

double q2(doublex,inty,intz)

{

x /=z;

y /=z;

returnx +y;

}

/ 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.

#include

usingnamespace std; /* SquareArea

* @params: width - the width of the square

* @returns: the area of the square

*/

int SquareArea(doublewidth)

{

returnwidth *width;

}

int main

{

cout <<"What is the width of the square? ";

cin << width;

cout <<"The area of the square is: " << SquareArea(width) << endl;

return 0

}

//Note: The program code contains 4 syntax errors and a logical error.

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?

string q2b(chara,intb,boolc)

{

string ret ="The ";

if (b % 3 > 0)

ret+="quick ";

else

ret+="slow ";

c = (!c ||c) && (a >='A' &&a <='Z');

if (c)

ret+="brown ";

else

ret+="blue ";

switch (b)

{

case 4:

ret+="fox";

break;

case 5:

ret+="penguin";

case 6:

ret+="bear";

break;

default:

ret+="cat";

}

return ret;

}

/ 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.

#include

usingnamespace std;

/* Calculator

* @params: command - the operation you want to perform (+, -, *, or /)

* op1, op2 - the 2 operands

* @returns: the calculated answer

*/

int Calculator(charcommand,intop1,intop2);

{

answer = 0;

switch command

{

case'+':

answer = op1 + op2;

case'-':

answer = op1 - op2;

case'*':

answer = op1 * op2;

case'/':

answer = op1 / op2;

}

return answer

}

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%)
  • Code contains no compile-time errors.
  • Code contains no logical errors.
  • Code produces the exact correct output and does not crash for valid inputs.
  • Code is well organized, clear, and easy to read.
  • Code is consistent throughout and comments are used where needed.
  • Code contains no compile-time errors.
  • Code produces the exact correct output except for a few formatting issues / incorrect data type issues.
  • Code does not crash for valid inputs.
  • Code produces the correct output most of the time. However, for some valid inputs, it shows the incorrect output.
  • Minor logical errors are present.
  • Code contains no compile-time errors.
  • Code is disorganized or could use some refactoring.
  • Code contains major logical errors and does not match the expected output.
  • Code contains compile-time errors.
  • Code contains major logical errors.
  • Code is very difficult to read.
  • Code does not execute.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!