Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92482754
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As