braching

3
Introduction to Computer Science Branching questions You often need to convert Rupees into coins of 5, 2, and 1 as your younger brother often asks you for some money in coins, to put them in his moneybox. Your brother can ask you for any amount of money like 33 Rupees or 54 Rupees etc. So you need to develop a program, which takes the amount of money in terms of rupees and then computes a mix of coins of 5, 2 and 1 against that money. Remember that you may not always have enough coins. So the program should be able to covert the money into the coins available. For example, if you don’t have the coins of 5-rupees, then for 7 rupees the program should compute a mix of 2-rupees and 1-rupee coins, i.e. 3 coins of 2-rupees and one coin of 1- rupee. For this program, assume that you always have enough number of 1-rupee coins against any amount of money. The program should also take as input the number of 5-rupees and 2-rupees coins available. The program should compute the amount of money in terms of numbers of 5-rupees coins, 2-rupees coins and 1-rupee coins. Write pseudocode for the program Exercise 1: The player makes three rolls of the dice. The player wins if the three rolls of the dice form the following sequence: First roll is a 5 or 6 Second roll is a 3 or 4 Third roll is a 1 or 2 Write a pseudo code for this problem that takes as input three values (rolls of dice) and prints “You won” if the three values (rolls of dice) follow the above sequence and “You lost” otherwise.

Upload: arxlan-xahir

Post on 07-Nov-2015

8 views

Category:

Documents


4 download

DESCRIPTION

c++

TRANSCRIPT

Write pseudo code & flow chart for the following program

Introduction to Computer Science

Branching questions

You often need to convert Rupees into coins of 5, 2, and 1 as your younger brother often asks you for some money in coins, to put them in his moneybox. Your brother can ask you for any amount of money like 33 Rupees or 54 Rupees etc. So you need to develop a program, which takes the amount of money in terms of rupees and then computes a mix of coins of 5, 2 and 1 against that money. Remember that you may not always have enough coins. So the program should be able to covert the money into the coins available. For example, if you dont have the coins of 5-rupees, then for 7 rupees the program should compute a mix of 2-rupees and 1-rupee coins, i.e. 3 coins of 2-rupees and one coin of 1-rupee. For this program, assume that you always have enough number of 1-rupee coins against any amount of money. The program should also take as input the number of 5-rupees and 2-rupees coins available. The program should compute the amount of money in terms of numbers of 5-rupees coins, 2-rupees coins and 1-rupee coins.

Write pseudocode for the program

Exercise 1:

The player makes three rolls of the dice. The player wins if the three rolls of the dice form the following sequence:

First roll is a 5 or 6

Second roll is a 3 or 4

Third roll is a 1 or 2

Write a pseudo code for this problem that takes as input three values (rolls of dice) and prints You won if the three values (rolls of dice) follow the above sequence and You lost otherwise.

Exercise 2:Suppose you are designing a game of tic tac toe. The user is x and the computer is o. Suppose during the game the following situation (on the left) is encountered:

OXaBc

xdEf

oxOgHi

Its the users turn to play (the o). Write pseudo code to take input from the user as to which box the user should enter the o. The cells are labeled from a to i' as shown above on the right. The user will enter the cell label where to put an o. After the user gives an input, its the computers turn to play. Your pseudo-code should then be able to decide which cell the computer has to put an x. As output you have to print who won the game or if it was a draw. (Consider the user enters a valid box label i.e. not any box label that is already taken).

Exercise 3:Write pseudo code for a program that takes input marks and Print the message accordingly. It will display following messages depend upon the marks.

Total Marks

Message

< 50

Fail

>50 & 60 & < 70

Grade C

>70 & < 80

Grade B

>80 &