Sie sind auf Seite 1von 4

CS100 Computational Problem Solving

Spring 2018-19, Section 1


Friday 29 March 2019
Lab 09: Exercise
Lab Guidelines
1. No mobile phones allowed. Turn off your phones and put them at a safe place (in your bag or on the
instructor’s desk). Anyone found with a phone will be marked zero.
2. Make sure you get your work graded before the lab time ends.
3. You put all your work onto the LMS folder designated for the lab (i.e. “Lab05”) before the time the lab ends.
4. Talking to each other is NOT permitted. If you have a question, ask the lab assistants.
5. The object is not simply to get the job done, but to get it done in the way that is asked for in the lab.
6. Any cheating case will be reported to Disciplinary Committee without any delay.
Coding Conventions:

1. Constants are ALL_CAPS.


2. Variables are all_small.
3. Functions are firstWordSmallRestCapitalized.
4. User defined data types AllWordsCapitalized.
5. All curly brackets defining a block must be vertically aligned.
Learning Objective:

1. PO-02 Develop proficiency in the practice of computing.


2. CO-02 To help students analyze and solve programming problems
3. LO-02 Critical Thinking and Analysis
4. LO-03 Problem Solving
5. LO-05 Responsibility
Marks: Name: _______________________ Roll #: ________________
Task1 Total
25
Total Marks
Obtained

Task2 Total
25
/100

Task 3 Total
25

TA: ______
Task 4 Total
25

Let’s Begin…
Task 1 [25 marks]
Following are the required pattern for number 2 and 3 respectively:

* *
*
* *

* * *
* *
*
* *
* * *
You have to write a program that takes a positive number 'n' as input and keeps on printing the
patterns for each number in the range 2 – n.
For further clarification see the sample output:

_____________________________________________________________________________________
Task 2 [25 marks]
Write a menu driven c++ program that allows the user to perform any of the following
operations to perform:
1. To compute the factorial of a given number
2. To tell whether a number is prime or not
3. To check whether a number is even or odd
The user should have the ability to choose either of these options. The program should
continue until user exits the program explicitly. See the below sample output carefully:

_____________________________________________________________________________________
Task 3 [25 marks]
Write a program in C++ to display a specific pattern of numbers for an integer input ‘n’. The
sample patterns for inputs 5 and 3 are the following:
Sample output:
Input number: 5
123454321
1234321
12321
121
1
Input number: 3
12321
121
1

_____________________________________________________________________________________

Task 4 [25 marks]


Write a function which takes a number in its argument and prints whether the number is
perfect or not. Test the function in main() by calling it multiple times with different argument
each time.
A perfect number is a positive integer that is equal to the sum of its proper positive divisors,
that is, the sum of its positive divisors excluding the number itself.
The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28,
496 and 8128.

_____________________________________________________________________________________

Das könnte Ihnen auch gefallen