Programming Fundamentals
Assignment 2
Due Date: 13 December 2020 (Sunday).
Total marks 40
Note: Do not copy code from internet or any other source even across the sections. I will check
the plagiarism of the assignment and it will capture the cheated code from internet or copied from
class fellows. Those who will try they will get some marks for their effort even you do not get
perfect solution. Copied & Shared work will score in negative grading. Assignment should be in
visual Studio. You will send the entire project in zipped file. After submission, no excuse will be
entertained. No assignment will be accepted after due date.
Q1. Write a c++ program that generates a random number between 0 and 20 and asks the
user to guess the number. If the user guesses it right, he wins otherwise ask him to
guess again. marks:10
Sample Run:
Enter a number greater than or equal to 0 and less than 20 : 15
Your guess is higher than the number.
Guess again!
Enter a number greater than or equal to 0 and less than 20 : 8
Your guess is lower than the number.
Guess again!
Enter a number greater than or equal to 0 and less than 20 : 10
You guessed the correct number !!!
Note: To generate a random number between 0-20 use following directives and
commands.
#include<cstdlib>
int main(){
srand(time(0)) // Initialize random number generator.
number = (rand() % 100) //Generates random number between 0 and 100
Q2.Write a C++ program to check whether a number entered by user is negative, positive
or equal to zero. Hint: Use else if. marks:2
Q3.Write a C++ program by checking the values of length and breadth whether it is a
rectangle or a square. Take the value of length and breadth from the user. Remember,
square sides length and breadth are equal. marks:2
Q4.Write a C++ program to check person is oldest and youngest among the 3. (just like
which is greater among 3 numbers we did in the class) . Use Nested if.
Assignment 2
Due Date: 13 December 2020 (Sunday).
Total marks 40
Note: Do not copy code from internet or any other source even across the sections. I will check
the plagiarism of the assignment and it will capture the cheated code from internet or copied from
class fellows. Those who will try they will get some marks for their effort even you do not get
perfect solution. Copied & Shared work will score in negative grading. Assignment should be in
visual Studio. You will send the entire project in zipped file. After submission, no excuse will be
entertained. No assignment will be accepted after due date.
Q1. Write a c++ program that generates a random number between 0 and 20 and asks the
user to guess the number. If the user guesses it right, he wins otherwise ask him to
guess again. marks:10
Sample Run:
Enter a number greater than or equal to 0 and less than 20 : 15
Your guess is higher than the number.
Guess again!
Enter a number greater than or equal to 0 and less than 20 : 8
Your guess is lower than the number.
Guess again!
Enter a number greater than or equal to 0 and less than 20 : 10
You guessed the correct number !!!
Note: To generate a random number between 0-20 use following directives and
commands.
#include<cstdlib>
int main(){
srand(time(0)) // Initialize random number generator.
number = (rand() % 100) //Generates random number between 0 and 100
Q2.Write a C++ program to check whether a number entered by user is negative, positive
or equal to zero. Hint: Use else if. marks:2
Q3.Write a C++ program by checking the values of length and breadth whether it is a
rectangle or a square. Take the value of length and breadth from the user. Remember,
square sides length and breadth are equal. marks:2
Q4.Write a C++ program to check person is oldest and youngest among the 3. (just like
which is greater among 3 numbers we did in the class) . Use Nested if.