This is study resource 3 for the 24-week cohort during the summer of 2019.
There are 11 questions in it. Questions 1 to 6 are coding in C++ and 7 to 11 are from Zybooks. I have shown the work for all of them except for the questions that I had wrong. I got points off from Questions 4 & 6. Unfortunately, I did not get any feedback. I hope it can help anyone.
Do not just copy and paste the answers, you must understand the content in order to do well in the NYU Bridge To Tandon program. Good luck!
Click here to see all the study resources.
- Question #1
- Question #2
- Question #3
- Question #4
- Question #5
- Question #6
- Question #7
- Question #8
- Question #9
- Question #10
- Question #11
Question #1
Write a program that computes how much a customer has to pay after purchasing two
items. The price is calculated according to the following rules:
- Buy one get one half off promotion: the lower price item is half price.
- If the customer is club card member, additional 10% off.
- Tax is added.
Inputs to the program include:
- Two items’ prices
- Have club card or not (User enters ‘Y’ or ‘y’ for “yes”; ‘N’ or ‘n’ for “no”)
- Tax rate (User enters the percentage as a number; for example, they enter 8.25 if the tax rate is 8.25%)
Program displays:
- Base price – the price before the discounts and taxes
- Price after discounts – the price after the buy one get one half off promotion and the member’s discount, if applicable
- Total price – the amount of money the customer has to pay (after tax).
Your program should interact with the user exactly as it shows in the following example:
Enter price of first item: 10 Enter price of second item: 20 Does customer have a club card? (Y/N): y Enter tax rate, e.g. 5.5 for 5.5% tax: 8.25 Base price: 30.0 Price after discounts: 22.5 Total price: 24.35625
#include <iostream>
using namespace std;
int main() {
double item1, item2, basePrice, taxEntered, taxCalculation, total;
double promotion = 0;
char membership;
cout << "Enter price of first item: ";
cin >> item1;
cout << "Enter price of second item: ";
cin >> item2;
cout << "Does customer have a club card? (Y/N): ";
cin >> membership;
cout << "Enter tax rate, e.g. 5.5 for 5.5% tax: ";
cin >> taxEntered;
basePrice = item1 + item2;
if (item1 < item2 && (membership == 'y' || membership == 'Y'))
promotion = 0.9 * (item2 + (item1 * 0.5));
else if (item2 < item1 && (membership == 'y' || membership == 'Y'))
promotion = 0.9 * (item1 + (item2 * 0.5));
else if (item1 == item2 && (membership == 'y' || membership == 'Y'))
promotion = 0.9 * (item1 + (item2 * 0.5));
else
promotion = item1 + (item2 * 0.5);
taxCalculation = 1 + (taxEntered * 0.01);
total = promotion * taxCalculation;
cout << "Base price: " << basePrice <<endl;
cout << "Price after discounts: " << promotion <<endl;
cout << "Total price: " << total <<endl;
return 0;
}
Question #2
Write a program that:
- Asks the user for their name.
- Asks the user to input their graduation year.
- Asks the user to input the current year.
Assume the student is in a four-year undergraduate program. Display the current status the
student is in. Possible status include: not in college yet, freshman, sophomore, junior, senior,
graduated.
Note: If graduation year equals to current year, status is ‘Graduated’; if graduation year is
four years after current year, status is ‘Freshman’, etc.
Your program should interact with the user exactly as it shows in the following example:
Please enter your name: Jessica Please enter your graduation year: 2019 Please enter current year: 2015 Jessica, you are a Freshman
#include <iostream>
#include <string>
using namespace std;
int main() {
string studentName;
int graduationYear, currentYear, gradStatus;
cout << "Please enter your name: ";
cin >> studentName;
cout << "Please enter your graduation year: ";
cin >> graduationYear;
cout << "Please enter current year: ";
cin >> currentYear;
gradStatus = graduationYear - currentYear;
if (gradStatus > 4)
cout << studentName << ", you are not in college yet.";
else if (gradStatus == 4)
cout << studentName << ", you are a Freshman.";
else if (gradStatus == 3)
cout << studentName << ", you are a Sophomore.";
else if (gradStatus == 2)
cout << studentName << ", you are a Junior.";
else if (gradStatus == 1)
cout << studentName << ", you are a Senior.";
else
cout << studentName << ", you are graduated.";
cout << endl;
return 0;
}
Question #3
Write a program that does the following:
- Ask user to input three Real numbers a, b and c. They represent the parameters of a quadratic equation 𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
- Classify to one of the following:
- ’Infinite number of solutions’ (for example, 0𝑥2 + 0𝑥 + 0 = 0 has infinite number of solutions)
- ’No solution’ (for example, 0𝑥2 + 0𝑥 + 4 = 0 has no solution)
- ’No real solution’ (for example, 𝑥2 + 4 = 0 has no real solutions)
- ’One real solution’
- ’Two real solutions’
- In cases there are 1 or 2 real solutions, also print the solutions.
Your program should interact with the user exactly as it shows in the following example:
Please enter value of a: 1 Please enter value of b: 4 Please enter value of c: 4 This equation has a single real solution x=-2.0
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c, det, sqRtDet, quadSolPos, quadSolNeg, quadSolDetZero;
cout << "Please enter value of a: ";
cin >> a;
cout << "Please enter value of b: ";
cin >> b;
cout << "Please enter value of c: ";
cin >> c;
det = pow(b, 2.0) - (4.0 * a * c);
sqRtDet = sqrt(det);
quadSolPos = (-b + sqRtDet)/(2.0*a);
quadSolNeg = (-b - sqRtDet)/(2.0*a);
quadSolDetZero = (-b)/(2.0*a);
if (a == 0)
cout << "This equation has no solution.";
else if (a == 0 && b == 0 && c == 0)
cout << "This equation has an infinite number of solutions.";
else if (det > 0)
cout << "This equation has two real solutions x = " << quadSolPos << " and " <<quadSolNeg;
else if (det == 0)
cout << "This equation has one real solution x = " << quadSolDetZero;
else if (det < 0)
cout << "This equation has no real solutions";
return 0;
}
Question #4
Define the following constants:
const int FLOOR_ROUND = 1; const int CEILING_ROUND = 2; const int ROUND = 3;
Write a program that asks the user to enter a Real number, then it asks the user to enter the
method by which they want to round that number (floor, ceiling or to the nearest integer).
The program will then print the rounded result.
Your program should interact with the user exactly as it shows in the following example:
Please enter a Real number: 4.78 Choose your rounding method: 1. Floor round 2. Ceiling round 3. Round to the nearest whole number 2 5
Implementation requirement: Use a switch statement.
#include <iostream>
using namespace std;
const int FLOOR_ROUND = 1;
const int CEILING_ROUND = 2;
const int ROUND = 3;
int main()
{
double realNum, roundNum;
int floorNum, ceilingNum;
int choiceInt;
cout << "Please enter a Real number: "<<endl;
cin >> realNum;
cout << "Choose your rounding method: "<<endl;
cout << "1. Floor round"<<endl;
cout << "2. Ceiling round"<<endl;
cout << "3. Round to the nearest whole number"<<endl;
cin >> choiceInt;
switch (choiceInt){
case FLOOR_ROUND:
floorNum = realNum;
cout<<floorNum<<endl;
break;
case CEILING_ROUND:
ceilingNum = realNum + 1;
cout<<ceilingNum<<endl;
break;
case ROUND:
floorNum = realNum;
ceilingNum = realNum + 1;
roundNum = realNum - floorNum;
if (roundNum < 0.5)
cout << floorNum<<endl;
else
cout << ceilingNum<<endl;
break;
default:
cout << realNum;
break;
}
return 0;
}
Question #5
Body mass index (BMI) is a number calculated from a person’s weight and height using the following formula: 𝑤𝑒𝑖𝑔ℎ𝑡/ℎ𝑒𝑖𝑔ℎ𝑡2. Where 𝑤𝑒𝑖𝑔ℎ𝑡 is in kilograms and ℎ𝑒𝑖𝑔ℎ𝑡 is in meters.
According to the Centers for Disease Control and Prevention, the BMI is a fairly reliable indicator of body fatness for most people. BMI does not measure body fat directly, but research has shown that BMI correlates to direct measures of body fat, such as underwater weighing and dual-energy X-ray absorptiometry.
Write a program that prompts for weight (in pounds) and height (in inches) of a person, and prints the weight status of that person.
Your program should interact with the user exactly as it shows in the following example:
Please enter weight (in pounds): 135 Please enter height (in inches): 71 The weight status is: Normal
Note: 1 pound is 0.453592 kilograms and 1 inch is 0.0254 meters.
#include <iostream>
#include <cmath>
using namespace std;
const double POUND_IN_KILOGRAM = 0.453592;
const double INCH_IN_METER = 0.0254;
int main() {
double weightPounds, weightKg, heightInches, heightMeters, heightSquare, bmi;
cout << "Please enter weight (in pounds): ";
cin >> weightPounds;
cout << "Please enter height (in inches): ";
cin >> heightInches;
weightKg = weightPounds * POUND_IN_KILOGRAM;
heightMeters = heightInches * INCH_IN_METER;
heightSquare = pow(heightMeters, 2);
bmi = weightKg/heightSquare;
if (bmi < 18.5)
cout << "This weight status is: Underweight.";
else if (bmi >= 18.5 && bmi < 25)
cout << "This weight status is: Normal.";
else if (bmi >= 25 && bmi < 30)
cout << "This weight status is: Overweight.";
else
cout << "This weight status is: Obese.";
return 0;
}
Question #6
Write a program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:
- Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.
- Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute.
- Any call started on a Saturday or Sunday is charged at a rate of $0.15 per minute.
The input will consist of the day of the week, the time the call started, and the length of the call in minutes. The output will be the cost of the call.
Notes:
- The time is to be input in 24-hour notation, so the time 1:30 P.M. is input as 13:30
- The day of the week will be read as one of the following two-character string: Mo Tu We Th Fr Sa Su
- The number of minutes will be input as a positive integer.
#include <iostream>
#include<string>
using namespace std;
const int MINUTES_IN_HOUR = 60;
const int EIGHT_AM_IN_MINUTES = 480;
const int SIX_PM_IN_MINUTES = 1080;
int main() {
string dayOfWeek;
int timeCallHour, timeCallMinutes, lengthOfCall, timeCallInMinutes;
double totalCost;
cout << "Enter the day of the week using 2 characters (e.g. Mo, Tu, We, Th, Fr, Sa, Su): ";
cin >> dayOfWeek;
cout << "Enter at what hour the call started (24-hour format - e.g. - 1PM = 13): ";
cin >> timeCallHour;
cout << "Enter at what minute the call started: ";
cin >> timeCallMinutes;
cout << "Enter the length of the call in minutes: ";
cin >> lengthOfCall;
timeCallInMinutes = timeCallHour * MINUTES_IN_HOUR + timeCallInMinutes;
if(dayOfWeek == "Mo" || dayOfWeek == "Tu" || dayOfWeek == "We" || dayOfWeek == "Th" || dayOfWeek == "Fr"){
if(timeCallInMinutes >= EIGHT_AM_IN_MINUTES && timeCallInMinutes <= SIX_PM_IN_MINUTES){
totalCost = (double) lengthOfCall * 0.40;
}else{
totalCost = (double) lengthOfCall * 0.25;
}
}else if (dayOfWeek == "Sa" || dayOfWeek == "Su") {
totalCost = (double) lengthOfCall * 0.15;
}else{
cout << "Invalid Request" << endl;
}
cout << "The cost of call is: $" << totalCost <<endl;
return 0;
}
Question #7
Exercise 3.1.1
a. 27 ∈ A = true – 27 is a multiple of 3
b. 27 ∈ B = false – 27 is not a perfect square
c. 100 ∈ B = true – square root of 100 is 10
d. E ⊆ C or C ⊆ E = False – not every element in E is an element of C
e. E ⊆ A = true – 3,6,9 are multiples of 3
f. A ⊂ E = false – 12 ∉ E
g. E ∈ A = false. E is not an element of A
Exercise 3.1.2
a. 15 ⊂ A = False – 15 is not a set
b. {15} ⊂ A = True – {15} is a proper set of A
c. ∅ ⊂ A = true – the empty set is a subset of every set
d. A ⊆ A = true – every set is a subset of itself
e. ∅ ∈ B = false – ∅ is a set. The elements in B are numbers, not sets
Exercise 3.1.5
b. {3, 6, 9, 12, ….} = {x ∈ Z: x is an integer multiple of 3} – Infinite
d. {0, 10, 20, 30, …., 1000} = {x ∈ N: x ≥ 0, x = 10x} – Finite, cardinality = 101
Exercise 3.2.1
a. 2 ∈ X = true – 2 is an element of set x
b. {2} ⊆ X = true – {2} is a subset of x
c. {2} ∈ X = false – set {2} is not an element of x
d. 3 ∈ X = false – 3 is not an element of x
e. {1, 2} ∈ X = true – set {1,2} is an element of x
f. {1, 2} ⊆ X = true
g. {2, 4} ⊆ X = true – {2,4} is included in set x
h. {2, 4} ∈ X = false – {2,4} is not an element of x
i. {2, 3} ⊆ X = false – {2,3} is not included in set x
j. {2, 3} ∈ X = false – {2,3} is not an element of x
k. |X| = 7 = false – cardinality is 6
Question #8
Exercise 3.2.4
b. Let A = {1, 2, 3}. What is {X ∈ P(A): 2 ∈ X}?
P(A) = {∅, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}
Since we are only looking for 2 ∈ X, then
{X ∈ P(A): 2 ∈ X} = {{2}, {1,2}, {2,3}, {1,2,3}}
Question #9
Exercise 3.3.1
I do not have the questions or answers.
Exercise 3.3.3
A.

= The only element will be 1 because there is no other element that intersects between A2 and A5. = {1}
B.

= {1, 2, 4, 3, 9, 16, 5, 25}
E.

= It will contain the least possible range of integers which is as given below as all the other sets will contain this as a subset. {x ∈ R: -1/100 ≤ x ≤ 1/100}
F.

= It will be the maximum possible which inlcudes -1/2 to ½ and so on untill -1/100 to 1/100. { x ∈ R: -1 ≤ x ≤ 1}
Exercise 3.3.4
b. P (A ∪ B) = {∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}
d. P (A) ∪ P (B) = {∅, {a}, {b}, {c}, {a, b}, {b, c}}
Question #10
Exercise 3.5.1
b. Write an element from the set B × A × C.
(foam, tall, non-fat)
c. Write the set B × C using roster notation.
{(foam, non-fat), (foam, whole), (no-foam, non-fat), (no-foam, whole)}
Exercise 3.5.3
b. Z2 ⊆ R2= true
c. Z2 ∩ Z3 = ∅ = true pairs and triples no elements in common
e. For any three sets, A, B, and C, if A ⊆ B, then A × C ⊆ B × C.
let (a, c) ∈ A x C
= a∈A, c∈C
= a∈B, c∈C
= (a, b) ∈ (BxC)
= A × C ⊆ B × C
= true
Exercise 3.5.6
d. {xy: where x ∈ {0} ∪ {0}2 and y ∈ {1} ∪ {1}2}
x = {0, 00}
y = {1, 11}
= {01, 011, 001, 0011}
e. {xy: x ∈ {aa, ab} and y ∈ {a} ∪ {a}2}
x = {aa, ab}
y = {a, aa}
= {aaa, aaaa, aba, abaa}
Exercise 3.5.7
c. (A × B) ∪ (A × C)
= {(a, b), (a, c)} ∪ {(a, a), (a, b), (a, d)}
= {(a, a), (a, b), (a, c), (a, d)}
f. P(A × B)
= {(a, b), (a, c)}
= {∅, {(a, b)}, {(a, c)}, {(a, b), (a, c)}}
g. P(A) × P(B). Use ordered pair notation for elements of the Cartesian product.
{(∅,∅), (∅,{b}), (∅, {c}), (∅,{b, c}), ({a}, ∅), ({a}, {b}), ({a}, {c}), ({a}, {b, c})}
Question #11
Exercise 3.6.2


Exercise 3.6.3
b. A – (B ∩ A) = A = False
Let
A = {a, b, c}
B = {a}
Then
B ∩ A = {a}
And
A – (B ∩ A) = {b, c}
A – (B ∩ A) ¹ A
d. (B – A) ∪ A = A = false
Let
A = {a, b, c}
B = {d}
Then
B – A = {d}
And
(B – A) ∪ A = {a, b, c, d}
(B – A) ∪ A != (not equal) A
Exercise 3.6.4
b. A ∩ (B – A) = ∅

c. A ∪ (B – A) = A ∪ B

Photo by Annie Spratt on Unsplash