Write a code that asks for two integers n and r where r


1. Multiplication Table

Part A

1. Write a code that asks for two integers, N and R, where R must be a factor of N (Check).

2. Write a code that prints out an N * N multiplication table in one line.

3. Suppose that R stands for number of entries printed in a row. Write a code which prints out an N * N multiplication table in R columns and (N/R) rows. For example, if N = 10 and R = 5, the output should be:

10 20 30 40 50

60 70 80 90 100

Part B

1. Modify 1A such that R can be any positive integer that is not larger than N (Check).

2. Write a code which prints out an N * N multiplication table in R columns and (N/R) rows. At times when R is not a factor of N, print the remaining numbers in a new row below. For example, when N = 10 and R = 4, the output should be:

10 20 30 40

50 60 70 80

90 100   .

Produce 1 script for part 1A and 1 script for part 1B. Ignore the dot.

2. Coin Flipping Again

In homework 1, the task was to flip 4 coins randomly. Now, we would like to flip any number of coins for a certain maximum number of times.

1 Write a code which asks the user to input the number of coins that they would like to flip as well as the maximum number of repetitions.

2. Write a code which flips the user-requested number of coins and prints the outcome in sequence. For example, in the case of 7 coins:
Outcome: 1 0 0 1 1 0 1

3. Modify your code such that it flips the coins over again for the user-requested number of repetitions. For example, in the case of 3 repetitions:

Outcome: 1 0 1 0 1 0 1
Outcome: 0 0 1 0 0 1 0
Outcome: 0 1 0 1 1 1 0

4. Modify your code to immediately stop repeating if the outcome is all tails. Before ending the program, display the total number of repetitions.

Produce 1 script for the entire Question 2.

3. Car Parking

Imagine you have a car park with 10 rows and 10 spaces available in each row. Next, assume that vehicles entering the car park can be described as size 1, 2, 3 or 4. Vehicles are to fully occupy a row before starting a new one. However, when a large vehicle enters, there may not be enough space in that row to accommodate it. In such an event, skip the remaining spaces and start the new row. End when the last row is completed.

Part A

1 Write a code which fills up a single row, ensuring that the number of spaces occupied is not exceeded. The vehicle size should be generated using (rand() % 4) + 1. When the row is filled up, report the number of vehicles in the row.

2 Modify your code such that records the size of the vehicle that was unable to fit into the remaining spaces of a row. For example, when there are 3 spaces left but a vehicle of size 4 enters the car park:

Extra vehicle = 4
No space for vehicle of size 4 in this row.

Part B

1. Write a code which fills up the 10 rows with vehicles. Each row may begin from 0 spaces occupied. Assume that vehicles that do not fit into remaining spaces are "rejected".

2. Modify your code such that the extra vehicle which does not fit into the end of the row is automatically placed at the start of the new row. For example, take this scenario where the vehicles entering the car park were of size: 3, 4, 2, 2:
0 spaces occupied in row 1
3 spaces occupied in row 1
7 spaces occupied in row 1
9 spaces occupied in row 1
No space in row 1 for vehicle of size 2 2 spaces occupied in row 2

Produce 1 script for part 3A and 1 script for part 3B.

4. Expense calculator

We would like to program a simple expense calculator which gives the user an option to choose between a daily tally and a weekly tally.

Part A

1 Write a code which requests the user to key in a daily allowance limit, followed by expenses. The expenses should be keyed in one by one. Recording of expenses should be terminated by entering „0?. Return the outcome of the sum of expenses as well as the remaining allowance, including negative values. Notify the user if expenses have exceeded allowance.

Part B

1 Modify your code to begin on the first day of the week. Thus, whenever „0? is entered, return the outcome as per 4A.1 and ask the user if they would like to move on to the next day of the week. If „N?, allow the user to "restart" the current day.

2 Modify your code to begin with asking the user if they would like to use the calculator in daily mode or weekly mode. In daily mode, the calculator should just ask to do_Again after it has completed one calculation. In weekly mode, the calculator should indicate the current day of the week.

[Hint: casting daily and weekly as functions can simplify your task.]

int main (void)
{
int choice;

printf("Daily or weekly? (1 / 2): "); scanf("%d", &choice); printf("\n\n");

if (choice == 1)
DAILY( ); // void DAILY (void), no inputs or outputs if (choice == 2)
WEEKLY( ); // void WEEKLY (void)

return 0;
}

Produce 1 script for part 4A and 1 script for part 4B.

Attachment:- sample output.rar

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Write a code that asks for two integers n and r where r
Reference No:- TGS02469583

Expected delivery within 24 Hours