You are on page 1of 2

Air University Multan Campus

Lab Mid Examination: Fall, 2020

Subject Programming Fundamental Total Marks 50


Course Code CS-111 L Date 18-12-2020
Class BS CS Fall 20 Time 10:00 AM – 12:30 PM
Semester 1st Max. Time Allowed 150 min (2 hr 30 min).
Section B Instructor Name Muhammad Yasir Khan
Signature

Note: Please read instructions carefully before start coding.

Question
Let’s play a game “Heads or Tails”. If you are already familiar with this game then great but if you
aren’t, here is a simple description of this game.
Heads or Tails is a cricket like game. It just does not include bat and ball. You have to play it with
your fingers. It’s a match between two players one is bowler and other is batsman. But before the
match begin there is a Toss. Player first tells what side of coin he will choose (Heads/Tails). Heads
is even number and Tails is odd number. Both player will throw a number between range 1 to 5.
If sum of both numbers is an even number than player who chose Heads will bat first and otherwise
the other player will bat first. The player will be considered out if both players throw same number
otherwise player who is batting will continues. Now how do we choose a winner?
A winner is the one whose total score is greater than the opponent’s total score. So if player A was
batting first and his score was (6+6+3+2+4+5+1+2+6+5+3+2 = 45) and B made more than that
score then B is winner and if B outs before achieving the target then A is winner. Player can score
between 1 to 6 on each turn and in a random format just like cricket but there is no dot ball.
Sound’s interesting. Right?
Now here is your task. Suppose there are two players A (user) and B (Computer). Computer will
randomly generate number between range 1 to 6 by using rand() function.
You have to write a program that will perform the following task.
o Choose Heads/Tail.
o Decide who will bat first (winner of the Toss).
o If Player A is winner then start input number in the specified range. And each
time when a number is input compare it with the player B’s number.
o Maintain the total score of each player of each player.
o If player A is out, then it’s player B turn. Maintain its total score and finally
announce the winner.
Optional:
Use an array to store final score and display on terminal.
Player Score
Player A 45
Player B 43

Submission Guidelines:
 Submit code file only on GCR.
 Rename with RollNo_Name_Mid.cpp format
 Any kind of cheating will lead to zero.
 Strictly follow timeline.
 On submission of paper after
o 12:30PM and before 02:30PM will penalize 20% of obtained marks.
o 02:30PM and before 03:30 will penalize 50% of obtained marks.
o Any submission after 04:00PM shall not be accepted and will lead to ZERO.

 Happy Coding 

You might also like