Posted on

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 #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

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

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

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

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

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:

  1. The time is to be input in 24-hour notation, so the time 1:30 P.M. is input as 13:30
  2. The day of the week will be read as one of the following two-character string: Mo Tu We Th Fr Sa Su
  3. 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

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

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

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

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

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.