Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assignment 01-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES ISLAMABAD

CAMPUS

CS-1002 Programming Fundamentals Fall-2023


ASSIGNMENT-01
Section (A, B, C, D, E, F and G)
Deadline: 21st September 2023 03:00 PM

Instructions:
• For each question in your assignment, make a separate cpp file e.g. for question 1, make ROLL-
NUM_SECTION_Q#.cpp (23i-0001_A_Q1.cpp) and so on. Each file that you submit must
contain your name, student-id, and assignment # on top of the file in comments.
• Combine all your work in one folder. The folder must contain only .cpp files (no binaries, no
exe files etc.).
• Rename the folder as ROLL-NUM_SECTION (e.g. 23i-0001_A) and compress the folder as a
zip file. (E.g. 23i-0001_A.zip). Do not submit .rar file.
• All the submissions will be done on Google classroom within the deadline. Submissions other
than Google classroom (e.g. email etc.) will not be accepted.
• The student is solely responsible to check the final zip files for issues like corrupt files, viruses
in the file, mistakenly exe sent. If we cannot download the file from Google classroom due to
any reason, it will lead to zero marks in the assignment.
• Displayed output should be well mannered and well presented. Use appropriate comments and
indentation in your source code.
• Be prepared for viva or anything else after the submission of assignment.
• If there is a syntax error in code, zero marks will be awarded in that part of assignment.
• Understanding the assignment is also part of assignment.
• The AIM of this assignment is to give you practice with arithmetic, bitwise and ternary
operators. Zero marks will be awarded if advance topics (e.g., if else, loops & arrays etc.)
used. Do not use any built-in function other than pow , log (#include <cmath>) setw and
setfill (#include <iomanip>).

• Zero marks will be awarded to the students involved in plagiarism. (Copying from the
internet is the easiest way to get caught).
• Late Submission policy will be applied as described in course outline.

Tip: For timely completion of the assignment, start as early as possible.


Note: Follow the given instruction to the letter, failing to do so will result in a zero.

1|P a ge
NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES ISLAMABAD
CAMPUS

Problem 01: NUCES Calculator


Write a C++ program that outputs the following using only one cout statement. Use setw and
setfill for spaces and repeated characters.

2|P a ge
NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES ISLAMABAD
CAMPUS

Problem 02: Rightmost digit


Write a program that accepts three non-negative integers from the user and print “true” if two or
more of them (Integers) have the same rightmost digit.
E.g.
Input the first number: 5
Input the second number: 10
Input the third number: 15
The result is: true
Note: Ternary operator not allowed

Problem 03: Credit Card Loan

Whereas:

N = How long it will take to pay off a credit card loan. (float)
c = A constant factor (int : value will be 30).
b = balance (int)
p = monthly payment (int)
i = yearly interest rate/365 (float)
ln = Natural logarithm
Write a program that takes these c, b, p and i as an inputs and gives an output. Note: use cmath
library for pow and log functions.

3|P a ge
NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES ISLAMABAD
CAMPUS

Problem 04: Bar Chart


Take 5 integer inputs from the user, then display bar chart using ‘*’ char. Hint [use iomanip library]
Input:
N1: 1 N2: 3 N3: 9 N4: 2 N5: 5
Output:
N1: *
N2: * * *
N3: * * * * * * * * *
N4: * *
N5: * * * * *
Note: Ternary operator not allowed. Use only setw() and setfill()
Problem 05: Magic Number
The date June 10, 1960, is special because when we write it in the following format, the month
times the day equal the year.
6/10/60
6×10=60
Write a C++ program that asks the user to enter a month (in numeric form), a day, and a two-digit
year. The program should then determine whether a month times the day is equal to the year. If so,
it should display a message saying the date is magic. Otherwise it should display a message saying
the date is not magic.
Problem 06: Quantum Key Generator
Design a Quantum Key Generator for a secure facility with the following requirements:
Input a positive integer (of 32 bits). The integer will contain 3 private gates and 1 Public
CONSTANT gate of 8 bits each. Your objective is to find the Quantum Key. The Quantum Key
must satisfy the following conditions:
Each key bit when XORed with the respective gate bits must equal the Constant Public Gate bit.
Note:
1. Use Bitwise Operators for Bit Manipulation (no arithmetic and Ternary operators allowed)
2. You must output the key byte in Binary form

4|P a ge
NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES ISLAMABAD
CAMPUS

An example of this is given below (note that all the bits in one row XORed equal to the same
Constant Bit). You must print the Key at the end. You have to find and display the key.
Input 32 bit positive number: 3584717002
1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0
Constant GATE3 GATE2 GATE1

Problem 07: Binary to Grey Code Converter:


Grey codes are binary numeral systems in which neighboring numbers have only one differing bit.
For converting a binary code to grey code, we simply record the MLB (Most Left Bit) as it is and
then, add MLB to its neighboring bit, record the sum and neglect the carry. Repeat the process.
The resulting number will be our grey code. This is how we convert binary code to grey code.
Write a program that takes any non-zero (16 bit) integer from the user and outputs its grey code
value in bits.
Note: use only bitwise operators
In the given picture, we record MLB as it is. Then we add 1 and 0, record the sum 1 and neglect
carry. And so on.

5|P a ge
NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES ISLAMABAD
CAMPUS

Problem 08: Bill Calculation


You have started working at a water plant and have been asked to develop a program which can
calculate the total water consumption bill. Your program will input the number of gallons from
the user and will calculate the total bill according to the following conditions:
 The first 100 gallons for $0.45/gallon
 The next 250 gallons for $0.85/gallon
 The next 250 gallons for $1.45/gallon
For additional gallons above 600 $2.60/gallon
An additional service charge of 14% is also added to the bill.
Your answer should be correct to 2 decimal places.
Note: Ternary operator not allowed
Problem 09:
Given four integers by the user, provide a program that displays the max and second maximum
value.
Problem 10: Find the Color
You are given a grid as shown in the figure below. You can determine the color and number of
each square from the grid. Write a C++ program that inputs two numbers within the grid range.
Your program will determine if the two squares entered in this grid have the same color or not.

------------------ Enjoy Codding because it is a great fun (Bill Gates) 😊 ------------------

6|P a ge

You might also like