0% found this document useful (1 vote)
197 views

Assignment 2

The document provides instructions for Assignment #2 for the course Programming Fundamentals (CS118) at National University of Computer & Emerging Sciences Islamabad Campus. It includes 10 questions to be answered in C++. Students are instructed to combine their solutions into a zip file with a specific naming convention and submit it by the deadline of October 11, 2019. Code should be properly commented and formatted or marks will be deducted. Plagiarism is not allowed and will result in zero marks.

Uploaded by

Muhammad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
197 views

Assignment 2

The document provides instructions for Assignment #2 for the course Programming Fundamentals (CS118) at National University of Computer & Emerging Sciences Islamabad Campus. It includes 10 questions to be answered in C++. Students are instructed to combine their solutions into a zip file with a specific naming convention and submit it by the deadline of October 11, 2019. Code should be properly commented and formatted or marks will be deducted. Plagiarism is not allowed and will result in zero marks.

Uploaded by

Muhammad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NATIONAL UNIVERSITY OF COMPUTER & EMERGING

SCIENCES ISLAMABAD CAMPUS


Programming Fundamentals (CS118)
FALL 2019 ASSIGNMENT # 2

Due Date: Friday, October 11, 2019 (1:00 pm)

Instructions:

Submission: Combine all your work (solution folder) in one .zip file. Use proper naming
convention for your submission file. Name the .zip file as ROLL-NUM_SECTION_02.zip (e.g.
19i-0001_H_02.zip). Submit zip file on slate within given deadline. Failure to submit according to
above format would result in deduction of 10% marks. Submissions on email will not be
accepted.

Comments: ​Comment your code properly. Bonus marks (maximum 10%) will be awarded to
well commented code. Write your name and roll number (as a block comment) at the beginning
of the solution of each problem.

Deadline: ​Deadline to submit assignment is 11th October, 2019 1:00 PM. Late submission ​with
marks deduction will be accepted according to the course policy shared earlier. Correct and
timely submission of the assignment is the responsibility of every student; hence no relaxation
will be given to anyone.

Tip: For timely completion of the assignment, start as early as possible. Furthermore, work
smartly - as some of the problems can be solved using smarter logic.

Plagiarism: Plagiarism is not allowed. If found plagiarized, you will be awarded zero marks in
the assignment.

Note:
Follow the given instruction to the letter, failing to do so will result in a zero.
Question 1: Write a C++ program to calculate the given below formula. The value of ​i needs to
be input by user while ​u​ = 1.234 and ​p​ = 3.334. (5 marks)

Question 2: Write a menu based C++ program that displays the user following three options.
You are ​not​ allowed to use loops for any of the patterns: (5+5+5 marks)

A. Draw an arrow pattern


B. Draw an X pattern
C. Draw a pyramid pattern

The user will enter one of the options and will be directed to the selected option as described
below:

Part A: ​This part of the program outputs arrow pattern using I/O manipulator <iomanip>
appropriately. You will input a string from the user and will draw the following pattern of strings
using that variable ​(Note: You cannot use any string literals containing white spaces in couts.)

Example:

Enter a string: ***

***
***
***
***
***
*********************
***
***
***
***
***

Part B: This part of the program outputs X pattern using I/O manipulator <iomanip>
appropriately. You will input a string from the user and will draw the following pattern of strings
using that variable. ​(Note: You cannot use any string literals containing white spaces in couts.)

Example:
Enter a string: ABCD

ABCD ABCD
ABCD ABCD
ABCD ABCD
ABCD ABCD
ABCD ABCD
ABCDABCD
ABCD ABCD
ABCD ABCD
ABCD ABCD
ABCD ABCD
ABCD ABCD

Part C: ​This part of the program outputs pyramid pattern using I/O manipulator <iomanip>
appropriately. You will input an integer number from the user and will draw the following pattern
of numbers using that variable. ​(Note: You cannot use any string literals containing white
spaces in couts.)

Example:

Enter a number: 1

1 1
1.0 1.0
1.00 1.00
1.000 1.000
1.0000 1.0000
1.00000 1.00000
1.000000 1.000000
1.0000000 1.0000000
1.00000000 1.00000000
1.000000000 1.000000000
1.0000000000 1.0000000000

Question 3: Write a C++ program to check whether an alphabet is vowel or consonant using
switch case. The program should accept upper and lower case alphabets. (5 marks)

Question 4: Write a C++ program to find roots of a quadratic equation using Ternary conditional
operator. (5 marks)
Question 5: You are given a 9*9 grid as shown in the figure below. You can determine the color
of each square from the grid. The number of each square is also shown below. Write a C++
program for this below given grid. The user is given two options to select from. (7.5+7.5 marks)

Part A: When the user selects 1st option, the user will enter number of square in this grid (any
number from 1-81). Your program will determine the color of the square.

Part B: ​When the user enters 2nd option, the user will enter two numbers from this grid. Your
program will determine if the two squares entered in this 9*9 grid have same color or not.

Question 6: ​UZone, a cellular company, provides the following three different postpaid data
packages for its customers. (5+5 marks)
● Package A: For Rs. 100 per month, 1 GB data is provided. Additional data can be
purchased for are Rs. 20 per 100 MB.
● Package B: For Rs. 200 per month, 2.5 GB data is provided. Additional data can be
purchased for are Rs. 10 per 100 MB.
● Package C: For Rs. 1000 per month, unlimited access is provided.

Part A: Write a program that calculates a customer’s monthly bill. It should ask how many GBs
the customer has used in the month and which package the customer has subscribed for. It
should then display the total amount due.
Part-B: Modify the Program in Part A so that it also displays how much money Package A
customers would save if they purchased packages B or C, and how much money Package B
customers would save if they purchased Package A or C. If there would be no savings for
particular package, it should print the appropriate message.

Question 7: Using switch statements only, write a C++ program that displays the following
menu for the food items available to take orders from the customer: (10 marks)
● Burgers
● Pizzas
● Sandwiches
When the user selects one of the options, a further submenu is displayed according to the
chosen option. The online food shop offers Crispy Chicken Burger, Beef Burger and Fish Burger
in the Burger category, Chicken tikka, Chicken Fajita and Four Seasons in the Pizza category
whereas Club, Chicken and Vegetables in the Sandwiches category. Prices of each food item is
also displayed to the user in the selected sub menu. The user will select the food item and
quantity of the item. In case of the Pizza items, the user can also select the size of pizzas (i.e.
Small ,Medium and Large). The program outputs the total charges according to the chosen
options.

Question 8: ​Write a C++ program which accepts amount in rupees as input (integer) within
Range from Rs. 100 to Rs. 100000 and then asks the user for particular currency note
preference and display the total number of Currency Notes of Rs. 500, 100, 50, 20, 10, 5 and 1.
The user can be given a maximum of 200 notes of his preferred choice. (5 marks)

For example: when a user enters a number, Rs. 57477 and enters 50 notes as his preferred
choice, the results would be like this.

Currency Note : Number


500 : 74
100 :4
50 : 200
20 :3
10 :1
5 :1
1 :2

Question 9:​ Write an astrology program in C++ according to the following criteria: (5+5 marks)

Part A: ​The user types in a birthday, and the program responds with the sign and horoscope for
that birthday. The month may be entered as a number from 1 to 12. Use a newspaper
horoscope section for the horoscopes and dates of each sign.
Part B: Then enhance your program so that if the birthday is only one or two days away from an
adjacent sign, the program announces that the birthday is on a “cusp” and also outputs the
horoscope for that nearest adjacent sign.

Question 10​: Write a C++ program of playing cards game. The game consists of the following
rules: (20 marks)
● The game has two players, with each player taking one turn each.
● Each player receives from two to five cards from the deck. (The 1st player decides how
many will be distributed to each)
● There are a total of maximum 52 cards in the deck. A "standard" deck of playing cards
consists of 52 Cards in each of the 4 suits of Spades, Hearts, Diamonds, and Clubs.
Each suit contains 13 cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King. .
● The cards 2 through 10 are scored as 2 through 10 points each. The face cards —Jack,
Queen and King — are scored as 10 points.
● The goal is to come as close to a score of 21 as possible without going over 21.
● Hence, any score over 21 is called “busted”.
● The ace card can count as either a 1 or 11, whichever is better for the user. For
example, an ace and a 10 can be scored as either 11 or 21. Since 21 is a better score,
this hand is scored as 21. An ace and two 8’s can be scored as either 17 or 27. Since 27
is a “busted” score, this hand is scored as 17.

The gameplay is given below:


● The 1st player is asked how many cards each player will receive, and the user responds
with one of the integers 2, 3, 4, or 5. Only one card value is chosen by each player - the
user choose any card except ace, while the rest of the cards are generated through
random values (ace can occur in random values). A good way to handle input is to use
the type char so that the card input 2, for example, is read as the character ’2’, rather
than as the number 2. Input the values 2 through 9 as the characters ’2’ through ’9’.
Input the values 10, jack, queen and king as the characters ’t’, ’j’, ’q’, ’k’, and ’a’. Be sure
to allow upper- as well as lowercase letters as input. After reading in the values, the
program should convert them from character values to numeric card scores. The output
for a particular player is either a number between 2 and 21 (inclusive) or the word
Busted. After turns of both players, the program shows the winner of the game (in case
one/both players scores under 21)

You might also like