Assignment 2 Loops

February 3, 2019 | Author: Ikram Nazeer | Category: Sales, Interest, Multiple Choice, Technology, Computing
Share Embed Donate


Short Description

Assignment 2 Loops...

Description

[Type the company name]

67

Lab Task 2.1

Write a program that display all possible odd numbers from 1 to 100 also calculate c alculate and display the sum of all these odd integers.

Lab Task 2.2

Write a program that asks the user to input a number and program should find the factorial of that number. Use appropriate prompt messages to illustrate your working. Lab Task 2.3

Write a program that will ask the user a question with four possible answers (Ask a MCQ type question and give him four choices). The question should be asked 10 times and after all inputs are gathered, the program should automatically calculate the number of times correct answer was selected and print the summary at the end of the test showing number of correct answers, incorrect answers and percentage of correct answers. If percentage is equal to or more than more than 70% print a well done message otherwise print a message stating that the user needs improvement. Sample Output: Q#1: What is answer of 4 + 5 1) 45 2) 40 3) 9 4) 45 Enter your option number here: 3 Well done! Your answer is correct! Q#2: What is name of the capital city of Pakistan 1) Lahore 2) Islamabad 3) Karachi 4) Quetta Enter your option number here: 1 Sorry your answer is incorrect. And so on. Result Summary: ---------------------Correct Answers = 7 out of 10 Incorrect Answers = 3 out of 10 Correct Percentage = 90% Status: Your General Knowledge is superb Lab Task 2.4

[Type the company name]

Write a program that inputs the number of students in the class. It then inputs the marks of each student and display the highest and second highest marks among these students. Use appropriate prompt messages to illustrate your working. Lab Task 2.5

Write a program that inputs two numbers from the user and display the first number raised to the power of second number. Lab Task 2.6

Write a program to print the square roots of the first 25 odd positive integers. Hint: Use sqrt()function and include library math.h Expected Output: Square root of 1 is: Square root of 3 is: Square root of 5 is: Square root of 7 is: Square root of 9 is: And so on till 25 Lab Task 2.7

A fabulously wealthy but unthinking king agreed to give a beggar one cent and double the amount for 24 days. Using this information, write, run, and test a C++ program that displays how much the king must pay the beggar on each day. The output of your program should appear as follows: Day 1 2 3 . . 24

Amount Owed 1 2 4 . . .

Lab Task 2.8

Convert a binary number to decimal. For this problem, you can input the total number of digits constituting the binary number and input the binary digits one by one from the user and print its decimal equivalent in the end. Lab Task 2.9

Write a program that sums a sequence of integers. Assume that the first integer read with cin or scanf specifies the number of values remaining to be entered. Your program should read only one value each time cin or scanf is executed. A typical input sequence might be 5

100

200

300

400

500

Where, 5 indicate that subsequent five values are to be summed. Lab Task 2.10

68

[Type the company name]

Write a program that accepts an upper limit from the user and it should display the following series up-to the upper limit specified in a n variable. 1

2

3

0

5

6

7

0

9

…………n

Lab Task 2.11

Write a program that ask the user to input two numbers in two variables x and n. Now compute and properly display the sum of following series.                    (  )  Lab Task 2.12

Write a program that asks the user to input a three digit number. The program should check that the given number is Armstrong or not. Note that a number is an Armstrong number if the sum of cubes of individual digits of that number is equal to the number itself. For example 371 is an Armstrong number as 3 3 + 73 + 13 = 371. Some other Armstrong numbers are: 0, 1, 153, 370, 407. Lab Task 2.13

Write a program that prompt the user to continuously input positive integer values to keep continue or enter zero to stop entering data. Now, the program should find and display the largest number among all entered numbers. Use appropriate prompt messages to illustrate the working of your program. Lab Task 2.14

Write a program to calculate and display the sum of following series 1/2 + 2/3 + 3/4 + 4/5 + 5/6 …… + 49/50 Lab Task 2.15

Write a program to ask the user to input a number and it should checks the given number on three parameters:   

Either the input number is odd or not Either the input number is even or not Either the input number is prime or not

For example the user enters 3 the program should display that the given number is odd and prime as well. Finally the program should prompt to enter (Y/N) to keep continue and provide another chance to test a number until the user enters N to stop entering data. Lab Task 2.16

Write a program that will take one integer variable “a”, one floating point numbers “b” from user and perform following operations and display the results.  sizeof(a);  sizeof(b);

69

[Type the company name]

   

++a +b a++ -b --a / b a-- *b

Lab Task 2.17

Because of the high price of petrol, you are concerned with the fuel consumption of your car. As a result you have a record of the kilometers driven and liters used for each tank of petrol you purchase. Write a program that will display the kilometers driven, liters used, and consumption (in liters/100km) for each tankful. After processing all the input information, the program should calculate the overall average consumption: Enter the litres used (-1 to end): 57.6 Enter the kilometres driven: 459 The litres/100km for this tank was 12.5 Enter the litres used (-1 to end): 45.3 Enter the kilometres driven: 320 The litres/100km for this tank was 14.2 Enter the litres used (-1 to end): -1 The overall average consumption was: 13.4 Lab Task 2.18

Write a programme that prints the ASCII table (from 33 to 256) on the screen. Remember: Character ASCII Code ! “ #

33 34 35

Lab Task 2.19

A car park charges a £2.00 minimum fee to park for up to 3 hours, and an additional £0.50 for each hour or part hour in excess of three hours. The maximum charge for any given 24-hour period is £10.00. Assume that no car parks for more than 24 hours at a time. Write a C program that will calculate and print the parking charges for each of 3 customers who parked their car in the car park yesterday. The program should accept as input the number of hours that each customer was parked, and output the results in a neat tabular form, along with the total receipts from the three customers:

Lab Task 2.20

Write a program that computes the cost of a long distance call. The following rate schedule is used for calculating the cost of a call.

70

[Type the company name]

1. Any call started between 8:00AM and 6:00PM, Monday through Friday, is billed at the rate of Rs. 24/- per minute. 2. Any call starting before 8:00AM or after 6:00PM, Monday through Friday, is charged at the rate of Rs. 15/- per minute. 3. Any call started on a Saturday or Sunday is charged at the rate of Rs. 9/- per minute. In your program, you will ask the user to provide input for three things: a. The day of week b. The time the call started c.

The length of the call in minutes

The day of week will be read as a single digit with following convention: 1 Mon

2 Tue

3

4

5

6

7

Wed

Thr

Fri

Sat

Sun

For the time the call started, the user will enter the time in 24-hour notation. So 1:30PM is entered as 1330. You can assume that user only enters valid inputs. The length of call shall be input as an int . You can assume the user rounds the length of call to a whole number. You can assume the user always enters a valid integer value here. The following is what your program should print out. The underlined letters represent what the user typed in.

Enter the day of your call: 1 Enter the time your call started in 24-hr notation: 1415 Enter the length of your call in minutes: 20 The cost of your call is Rs. 480 Do you want to do another calculation? (1 for yes and 0 to quit): 1 Enter the day of your call: 12 Bad_input. Enter the day of your call: -2 Bad_input. Enter the day of your call: 7 Enter the time your call started in 24-hr notation: 1230 Enter the length of your call in minutes: 40 The cost of your call is Rs. 360 Do you want to do another calculation? (1 for yes and 0 to quit): 0 Press any key to continue….

71

[Type the company name]

Note: Underlined text is input from user. Lab Task 2.21

A person invests $1000.0 in a savings account yielding 5% interest. Assuming that all interest is left on deposit in the account, calculate and print the amount of money in the account at the end of each year for 10 years. Use the following formula for determining these amounts: a = p(1+r)n where p r n a

is the original investment(i.e. the principal) is the annual interest rate is the number of years is the amount on deposit at the end of the nth year.

Sample output Year

1 2 3 4 5 6 7 8 9 10

Amount on deposit

1050.00 1102.50 1157.63 1215.51 1276.28 1340.10 1407.10 1477.46 1551.33 1628.89

Lab Task 2.22

In this task you will design ATM software. Most of you have idea how an ATM machine works? Your program will display a menu to user when executed. Menu is given below 1. Cash Withdrawal 2. Balance Transfer 3. Balance Inquiry You will ask user to enter the number of corresponding option like 1, 2 or 3. And will perform the operation accordingly. If user enters invalid option then error message will be displayed. Program will ask user again and again until user quits. Remember user can’t withdraw an amount that is greater than current balance. And you don’t need to be worry about what account number he enters in 2 nd option at present. You can set the initial balance of Rs.1000 An example is shown below:

72

[Type the company name]

Lab Task 2.23

Write a C program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: 1. 2. 3. 4. 5.

Account number Balance at beginning of month Total of all items charged by the customer this month Total of all credits applied to the account this month Allowed credit limit

The program should input each of these facts, calculate the new balance (initial balance + charges credits) and determine if the new balance exceeds the credit limit. If it does, a suitable message should be displayed. Enter account number (-1 to end): 100 Enter initial balance: 5394.78 Enter total charges: 1000 Enter total credits: 500.00 Enter credit limit: 5500.00  Account: 100 Credit limit: 5500 Balance: 5894.78

73

[Type the company name]

Credit Limit Exceeded Enter account number (-1 to end): 200 Enter initial balance: 1000.00 Enter total charges: 123.45 Enter total credits: 321.00 Enter credit limit: 1500.00  Account: 200 Credit limit: 1500 Balance: 802.45

Lab Task 2.24

A large chemical company pays its sales staff on a commission basis. They receive £200 per week plus 9% of their gross sales for that week. For example, someone who sells £5000 of chemicals in one week will earn £200 plus 9% of £5000, a total of £650. Develop a C program that will input each salesperson’s sales for the previous week, and print out their salary. Process one person’s figures at a time. Enter sales in pounds (-1 to end): 5000.00 Salary is: 650.00 Enter sales in pounds (-1 to end): 00.00 Salary is: 200.00 Enter sales in pounds (-1 to end): 1088.89 Salary is: 298.00 Enter sales in pounds (-1 to end): -1

74

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF