Posted on

This is Study Resource 2 for Summer 2019 – 24-week cohort.

There are 9 questions in it. Questions 1 to 4 are coding in C++ and 5 to 9 are from Zybooks. I have shown the work for all of them except for the questions that I had wrong. I know they are correct answers since I got feedback on Gradescope.

I hope it helps anyone and please, do not just copy and paste, you must understand the content in order to do well in the NYU Bridge To Tandon program.

Click here to see all the study resources.

Question #1

## Question #1

Write a program that asks the user to enter a number of quarters, dimes, nickels and
pennies and then outputs the monetary value of the coins in the format of dollars and
remaining cents.
Your program should interact with the user exactly as it shows in the following example:

Please enter number of coins:

# of quarters: 13

# of dimes: 4

# of nickels: 11

# of pennies: 17

The total is 4 dollars and 37 cents

```#include <iostream>
using namespace std;

const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;
const int PENNY = 1;

int main() {

int numberOfQuarters, numberOfDimes, numberOfNickels, numberOfPennies;
int totalNumberCoins, totalAmountDollar, totalAmountCents;

cout << "Please enter number of coins:" << endl;
cout << "# of quarters: ";
cin >> numberOfQuarters;

cout << "# of dimes: ";
cin >> numberOfDimes;

cout << "# of nickels: ";
cin >> numberOfNickels;

cout << "# of pennies: ";
cin >> numberOfPennies;

totalNumberCoins = (numberOfQuarters * QUARTER) + (numberOfDimes * DIME) +
(numberOfNickels * NICKEL) + (numberOfPennies * PENNY);

totalAmountDollar = totalNumberCoins / 100;
totalAmountCents = totalNumberCoins % 100;

cout << "The total is " << totalAmountDollar << " dollar(s) and " << totalAmountCents <<" cent(s)." << endl;

return 0;
}
```
Question #2

## Question #2

Write a program that asks the user to enter an amount of money in the format of dollars and
remaining cents. The program should calculate and print the minimum number of coins
(quarters, dimes, nickels and pennies) that are equivalent to the given amount.
Hint: In order to find the minimum number of coins, first find the maximum number of
quarters that fit in the given amount of money, then find the maximum number of dimes
that fit in the remaining amount, and so on.
Your program should interact with the user exactly as it shows in the following example:

```Please enter your amount in the format of dollars and cents separated by a space:
4 37
4 dollars and 37 cents are:
17 quarters, 1 dimes, 0 nickels and 2 pennies ```
```#include <iostream>
using namespace std;

const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;
const int PENNY = 1;

int main() {

int dollarAmount, centAmount;
int totalAmount, totalQuarters, totalDimes, totalNickels, totalPennies;
int remainingAmount;

cout << "Please enter your amount in the format of dollars and cents separated by a space:" << endl;
cin >> dollarAmount >> centAmount;

totalAmount = (dollarAmount * 100) + centAmount;

totalQuarters = totalAmount / QUARTER; //get how many quarters in the total amount
remainingAmount = totalAmount % QUARTER;

totalDimes = remainingAmount / DIME; //get how many dimes from the remaining amount.
remainingAmount = remainingAmount % DIME;

totalNickels = remainingAmount / NICKEL;
remainingAmount = remainingAmount % NICKEL;

totalPennies = remainingAmount / PENNY;

cout << endl;
cout << dollarAmount << " dollar(s) and " << centAmount << " cent(s) are:" <<endl;

cout << totalQuarters << " quarter(s)\t" << totalDimes << " dime(s)\t" << totalNickels <<" nickel(s)\t" << totalPennies << " penn(ies)";

cout << endl;
return 0;
}
```
Question #3

## Question #3

Suppose John and Bill worked for some time and we want to calculate the total time both of them worked. Write a program that reads number of days, hours, minutes each of them
worked, and prints the total time both of them worked together as days, hours, minutes.
Hint: Try to adapt the elementary method for addition of numbers to this use.
Your program should interact with the user exactly as it shows in the following example:

```Please enter the number of days John has worked: 2
Please enter the number of hours John has worked: 12
Please enter the number of minutes John has worked: 15
Please enter the number of days Bill has worked: 3
Please enter the number of hours Bill has worked: 15
Please enter the number of minutes Bill has worked: 20

The total time both of them worked together is: 6 days, 3 hours and 35 minutes.```
```#include <iostream>
using namespace std;

const int MINUTES_IN_DAY = 1440;
const int MINUTES_IN_HOUR = 60;

int main() {

int daysJohnWorked, daysBillWorked, hoursJohnWorked, hoursBillWorked, minutesJohnWorked, minutesBillWorked;
int totalHoursWorked, totalMinutesWorked, totalDaysWorked, remainingTime, totalTimeInMinutes;

cout << "Please enter the number of days John has worked: ";
cin >> daysJohnWorked;
cout << "Please enter the number of hours John has worked: ";
cin >> hoursJohnWorked;
cout << "Please enter the number of minutes John has worked: ";
cin >> minutesJohnWorked;

cout << endl;

cout << "Please enter the number of days Bill has worked: ";
cin >> daysBillWorked;
cout << "Please enter the number of hours Bill has worked: ";
cin >> hoursBillWorked;
cout << "Please enter the number of minutes Bill has worked: ";
cin >> minutesBillWorked;

totalTimeInMinutes = ( (daysJohnWorked + daysBillWorked ) * MINUTES_IN_DAY  ) +  ( (hoursJohnWorked + hoursBillWorked) * MINUTES_IN_HOUR ) + minutesJohnWorked + minutesBillWorked;

cout << endl;

totalDaysWorked = totalTimeInMinutes / MINUTES_IN_DAY;
remainingTime = totalTimeInMinutes % MINUTES_IN_DAY;

totalHoursWorked =  remainingTime / MINUTES_IN_HOUR;
remainingTime = remainingTime % MINUTES_IN_HOUR;

totalMinutesWorked = remainingTime;

cout << endl;

cout << "The total time both of them worked together is: " << totalDaysWorked << " days, " << totalHoursWorked
<< " hours and " << totalMinutesWorked << " minutes." << endl;

cout << endl;

return 0;
}
```
Question #4

## Question #4

Write a program that reads from the user two positive integers, and prints the result of
when we add, subtract multiply, divide, div and mod them.
Your program should interact with the user exactly as it shows in the following example:

```Please enter two positive integers, separated by a space:
14 4
14 + 4 = 18
14 – 4 = 10
14 * 4 = 56
14 / 4 = 3.5
14 div 4 = 3
14 mod 4 = 2```
```#include <iostream>
using namespace std;

int main() {

int num1, num2;
int addition, subtraction, multiplication, div, mod;
double division;

cout << "Please enter two positive integers, separated by a space: " << endl;

cin >> num1 >> num2;

addition = num1 + num2;
subtraction = num1 - num2;
multiplication = num1 * num2;
division = (double) num1 / (double) num2;
div = num1 / num2;
mod = num1 % num2;

cout << num1 << " + " << num2 << " = " << addition<< endl;
cout << num1 << " - " << num2 << " = " << subtraction<< endl;
cout << num1 << " * " << num2 << " = " << multiplication<< endl;
cout << num1 << " / " << num2 << " = " << division<< endl;
cout << num1 << " div " << num2 << " = " << div<< endl;
cout << num1 << " mod " << num2 << " = " << mod<< endl;

return 0;
}
```
Question #5

## Question #5

A. Solve the following questions:

Exercise 1.12.2

b.

p → (q ∧ r)

¬q

————–

∴ ¬p

e.

p ∨ q

¬p ∨ r

¬q

——–

∴ r

Exercise 1.12.3

c. One of the rules of inference is Disjunctive syllogism:

p ∨ q

¬p

——

∴ q

Prove that Disjunctive syllogism is valid using the laws of propositional logic and any of the other rules of inference besides Disjunctive syllogism. (Hint: you will need one of the conditional identities from the laws of propositional logic).

Exercise 1.12.5

c.

I will buy a new car and a new house only if I get a job.

I am not going to get a job.

————————————————————————-

∴ I will not buy a new car.

d.

I will buy a new car and a new house only if I get a job.

I am not going to get a job.

I will buy a new house.

————————————————————————

I will not buy a new car.

B. Solve the following questions:

Exercise 1.13.3

b:

∃x (P(x) ∨ Q(x))

∃x ¬Q(x)

——————–

∴ ∃x P(x)

Exercise 1.13.5

d.

Every student who missed class got a detention.

Penelope is a student in the class.

Penelope did not miss class.

—————————————————————

Penelope did not get a detention.

e.

Every student who missed class or got a detention did not get an A.

Penelope is a student in the class.

Penelope got an A.

—————————————————————————————–

Penelope did not get a detention.

Question #6

## Question #6

Exercise 2.2.1

d: The product of two odd integers is an odd integer.

c: If x is a real number and x ≤ 3, then 12 – 7x + x2 ≥ 0.

Question #7

## Question #7

Exercise 2.3.1

d: For every integer n, if n2−2n+7 is even, then n is odd.

f: For every non-zero real number x, if x is irrational, then 1/x is also irrational.

g: For every pair of real numbers x and y, if x3+xy2≤x2y+y3, then x≤y.

l: For every pair of real numbers x and y, if x + y > 20, then x > 10 or y > 10.

Question #8

## Question #8

Exercise 2.4.1

c: The average of three real numbers is greater than or equal to at least one of the numbers.

e: There is no smallest integer.

Question #9

## Question #9

Exercise 2.5.1

c: If integers x and y have the same parity, then x + y is even.

The parity of a number tells whether the number is odd or even. If x and y have the same parity, they are either both even or both odd.

Photo by Daniel Chekalov on Unsplash

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