SlideShare a Scribd company logo
OOP Lab Assignment 01
Problems Solving List:
1. Write a program that sorts three integers ascendingly. The integers are entered from
the input dialogs and stored in variables num1, num2, and num3,respectively.
Input: 50 1 90
Output: 1 50 90
2. Write a program that prompts the user to enter an integer and checks whether the
number is divisible by both 5 and 6, or neither of them, or just one of them.
Here are some sample runs for inputs 10, 30, and 23.
10 is divisible by 5 or 6, but not both
30 is divisible by both 5 and 6
23 is not divisible by either 5 or 6
3. Write a program that reads three edges for a triangle and determines whether the
input is valid. The input is valid if the sum of any two edges is greater than the third
edge. Here are the sample runs of this program:
Input: 1 2.5 1
Output: false
Input: 5 10 11
Output: true
4.
The problem is to write a program that computes loan payments. The loan can be a car
loan, a student loan, or a home mortgage loan. The program lets the user enter the
interest rate, number of years, and loan amount, and displays the monthly and total
payments.The formula to compute the monthly payment is as follows:
You don’t have to know how this formula is derived. Nonetheless, given the
monthly interest rate, number of years, and loan amount, you can use it to compute the
monthly payment.
**Compute the total payment, which is the monthly payment multiplied by 12 and
multiplied by the number of years.
5. Write a program that reads an integer between 0 and 1000 and adds all the digits in
the integer. For example, if an integer is 932, the sum of all its digits is 14.
Hint: Use the % operator to extract digits, and use the / operator to remove the
extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.
Input: 999
Output: 27
6. Write a program that receives an ASCII code (an integer between 0 and 128) and
displays its character. For example, if the user enters 97, the program displays a
character.
Input: 69
Output: E
7. Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and
displays their distances. The formula for computing the distance is
Input: Enter x1 and y1: 1.5 -3.4
Enter x2 and y2: 4 5
Output: The distance of the two points is 8.764131445842194
8. Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of
a triangle and displays its area. The formula for computing the area of a triangle is
Input: Enter three points for a triangle: 1.5 -3.4 4.6 5 9.5 -3.4
Output: The area of the triangle is 33.6
9. (Counting positive and negative numbers and computing the average of numbers) Write
a program that reads an unspecified number of integers, determines how many
positive and negative values have been read, and computes the total and average
of the input values (not counting zeros). Your program ends with the input 0. Display
the average as a floating-point number.
a. Sample Input: 1 2 -1 3 0
b. Sample Output:
The number of positives is: 3
The number of negatives is: 1
The total is : 5
The average is: 1.25
10. (Conversion from kilograms to pounds) Write a program that displays the following
table (note that 1 kilogram is 2.2 pounds):
Kilograms Pounds
1 2.2
3 6.6
...
197 433.4
199 437.8
11. Write a program that reads an 10 student scores and determines
a. Average score and print it
b. how many scores are above or equal to the average
c. and how many scores are below the average.
Enter a negative number to signify the end of the input.
12. Write a program that reads in ten numbers and displays distinct numbers (i.e., if a
number appears multiple times, it is displayed only once). Hint: Read a number and
store it to an array if it is new. If the number is already in the array, ignore it. After the
input, the array contains the distinct numbers.
Here is the sample run of the program:
Enter ten numbers:1 2 3 6 4 5 1 2 3 2
The distinct numbers are: 1 6 3 4 5 2
a. displays count of distinct numbers
13. (Math: combinations) Write a program that prompts the user to enter 10 integers
and displays all combinations of picking two numbers from the 10.
14. Write a program to sort n numbers in decreasing order. The program will take an
integer n: how many numbers following the n numbers.
a. Sample Input: 5
3 9 1 5 12
Sample Output: 12 9 5 3 1
15. (Checking password) Some Websites impose certain rules for passwords. Write a
method that checks whether a string is a valid password. Suppose the password rule is
as follows:
■ A password must have at least eight characters.
■ A password consists of only letters and digits.
■ A password must contain at least two digits.
Write a program that prompts the user to enter a password and displays "Valid
Password" if the rule is followed or "Invalid Password" otherwise.
16. * (Occurrences of a specified character) Write a function named “countChar” that finds
the number of occurrences of a specified character in the string. For example,
countChar("Welcome", 'e') returns 2. Write a test program that prompts the user to enter
a string followed by a character and displays the number of occurrences of the character
in the string.
17. **(Common prefix) Write a function that returns the common prefix of two strings. For
example, the common prefix of "distance" and "disinfection" is "dis". If the two strings
have no common prefix, the function returns an empty string.
Write a main function that prompts the user to enter two strings and display their
common prefix.
LAB Performance 01:
Write a program that
1) Take two numbers T and N as an input. T & N both are integers. T
representthe test case.Foreach T
2) Find the divisors/factorsof N
3) For each test case print the case no and factors of the given number
Sample Input: 3
6 4 2
Sample Output:
Case 1: 1 2 3 6
Case 2: 1 2 4
Case 3: 1 2

More Related Content

What's hot (20)

PDF
Pseudocode By ZAK
Tabsheer Hasan
 
DOC
Md university cmis 102 week 4 hands on lab new
scottbrownnn
 
DOC
Md university cmis 102 week 4 hands on lab new
eyavagal
 
DOCX
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Rc Os
 
PPTX
Operators
Allah Ditta
 
PDF
I PUC CS Lab_programs
Prof. Dr. K. Adisesha
 
PDF
CP Handout#7
trupti1976
 
PDF
SPL 12.1 | Multi Dimensional(Two) Array Practice Problems
Mohammad Imam Hossain
 
PPT
Beginner C++ easy slide and simple definition with questions
khawajasharif
 
PPTX
Basic concepts of python
deepalishinkar1
 
DOCX
C programming Lab 1
Zaibi Gondal
 
PDF
Year 2 dsa c++ exercises on user defined functions
ErnesteNtezirizaza
 
PDF
CP Handout#8
trupti1976
 
PDF
Python - Control Structures
LasithNiro
 
PDF
CP Handout#9
trupti1976
 
PDF
Cp manual final
itprasad1237
 
PPT
Beginner C++ easy slide and simple definition with questions
khawajasharif
 
PPTX
2. introduction of a c program
Alamgir Hossain
 
PDF
Java programlist (1)
Aditya Aggarwal
 
PPTX
3. user input and some basic problem
Alamgir Hossain
 
Pseudocode By ZAK
Tabsheer Hasan
 
Md university cmis 102 week 4 hands on lab new
scottbrownnn
 
Md university cmis 102 week 4 hands on lab new
eyavagal
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Rc Os
 
Operators
Allah Ditta
 
I PUC CS Lab_programs
Prof. Dr. K. Adisesha
 
CP Handout#7
trupti1976
 
SPL 12.1 | Multi Dimensional(Two) Array Practice Problems
Mohammad Imam Hossain
 
Beginner C++ easy slide and simple definition with questions
khawajasharif
 
Basic concepts of python
deepalishinkar1
 
C programming Lab 1
Zaibi Gondal
 
Year 2 dsa c++ exercises on user defined functions
ErnesteNtezirizaza
 
CP Handout#8
trupti1976
 
Python - Control Structures
LasithNiro
 
CP Handout#9
trupti1976
 
Cp manual final
itprasad1237
 
Beginner C++ easy slide and simple definition with questions
khawajasharif
 
2. introduction of a c program
Alamgir Hossain
 
Java programlist (1)
Aditya Aggarwal
 
3. user input and some basic problem
Alamgir Hossain
 

Similar to Oop lab assignment 01 (20)

DOCX
Important C program of Balagurusamy Book
Abir Hossain
 
DOCX
Java Practice Set
Gaurav Dixit
 
PDF
Xi CBSE Computer Science lab programs
Prof. Dr. K. Adisesha
 
PDF
xii cs practicals
JaswinderKaurSarao
 
PDF
Exercise1 java
NguynMinh294
 
PPTX
Basic pogramming concepts
Anurag Prajapat
 
PDF
Introduction to Basic C++ Program Examples .pdf
simegnew Ataley
 
PDF
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
PDF
Sasin nisar
SasinNisar
 
PDF
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
DOCX
Best c programs
AbhishekSharma471920
 
PDF
Simple c-programs
rashmi322
 
PDF
xii cs practicals class 12 computer science.pdf
gmaiihghtg
 
PPTX
ANSHUL RANA - PROGRAM FILE.pptx
jeyel85227
 
DOCX
Chapter 8Exercise1.Design an application that accept.docx
tiffanyd4
 
PDF
Sample Program file class 11.pdf
YashMirge2
 
PDF
python_lab_manual_final (1).pdf
keerthu0442
 
DOCX
Basic python laboratoty_ PSPP Manual .docx
Kirubaburi R
 
DOCX
List of programs to practice for ICSE
Mokshya Priyadarshee
 
Important C program of Balagurusamy Book
Abir Hossain
 
Java Practice Set
Gaurav Dixit
 
Xi CBSE Computer Science lab programs
Prof. Dr. K. Adisesha
 
xii cs practicals
JaswinderKaurSarao
 
Exercise1 java
NguynMinh294
 
Basic pogramming concepts
Anurag Prajapat
 
Introduction to Basic C++ Program Examples .pdf
simegnew Ataley
 
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
Sasin nisar
SasinNisar
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
Best c programs
AbhishekSharma471920
 
Simple c-programs
rashmi322
 
xii cs practicals class 12 computer science.pdf
gmaiihghtg
 
ANSHUL RANA - PROGRAM FILE.pptx
jeyel85227
 
Chapter 8Exercise1.Design an application that accept.docx
tiffanyd4
 
Sample Program file class 11.pdf
YashMirge2
 
python_lab_manual_final (1).pdf
keerthu0442
 
Basic python laboratoty_ PSPP Manual .docx
Kirubaburi R
 
List of programs to practice for ICSE
Mokshya Priyadarshee
 
Ad

Recently uploaded (20)

PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
PDF
smart lot access control system with eye
rasabzahra
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Thermal runway and thermal stability.pptx
godow93766
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
smart lot access control system with eye
rasabzahra
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Ad

Oop lab assignment 01

  • 1. OOP Lab Assignment 01 Problems Solving List: 1. Write a program that sorts three integers ascendingly. The integers are entered from the input dialogs and stored in variables num1, num2, and num3,respectively. Input: 50 1 90 Output: 1 50 90 2. Write a program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, or neither of them, or just one of them. Here are some sample runs for inputs 10, 30, and 23. 10 is divisible by 5 or 6, but not both 30 is divisible by both 5 and 6 23 is not divisible by either 5 or 6 3. Write a program that reads three edges for a triangle and determines whether the input is valid. The input is valid if the sum of any two edges is greater than the third edge. Here are the sample runs of this program: Input: 1 2.5 1 Output: false Input: 5 10 11 Output: true 4. The problem is to write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest rate, number of years, and loan amount, and displays the monthly and total payments.The formula to compute the monthly payment is as follows: You don’t have to know how this formula is derived. Nonetheless, given the monthly interest rate, number of years, and loan amount, you can use it to compute the monthly payment. **Compute the total payment, which is the monthly payment multiplied by 12 and multiplied by the number of years.
  • 2. 5. Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93. Input: 999 Output: 27 6. Write a program that receives an ASCII code (an integer between 0 and 128) and displays its character. For example, if the user enters 97, the program displays a character. Input: 69 Output: E 7. Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distances. The formula for computing the distance is Input: Enter x1 and y1: 1.5 -3.4 Enter x2 and y2: 4 5 Output: The distance of the two points is 8.764131445842194 8. Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is Input: Enter three points for a triangle: 1.5 -3.4 4.6 5 9.5 -3.4 Output: The area of the triangle is 33.6 9. (Counting positive and negative numbers and computing the average of numbers) Write a program that reads an unspecified number of integers, determines how many
  • 3. positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. a. Sample Input: 1 2 -1 3 0 b. Sample Output: The number of positives is: 3 The number of negatives is: 1 The total is : 5 The average is: 1.25 10. (Conversion from kilograms to pounds) Write a program that displays the following table (note that 1 kilogram is 2.2 pounds): Kilograms Pounds 1 2.2 3 6.6 ... 197 433.4 199 437.8 11. Write a program that reads an 10 student scores and determines a. Average score and print it b. how many scores are above or equal to the average c. and how many scores are below the average. Enter a negative number to signify the end of the input. 12. Write a program that reads in ten numbers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once). Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it. After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter ten numbers:1 2 3 6 4 5 1 2 3 2 The distinct numbers are: 1 6 3 4 5 2 a. displays count of distinct numbers 13. (Math: combinations) Write a program that prompts the user to enter 10 integers and displays all combinations of picking two numbers from the 10. 14. Write a program to sort n numbers in decreasing order. The program will take an integer n: how many numbers following the n numbers.
  • 4. a. Sample Input: 5 3 9 1 5 12 Sample Output: 12 9 5 3 1 15. (Checking password) Some Websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rule is as follows: ■ A password must have at least eight characters. ■ A password consists of only letters and digits. ■ A password must contain at least two digits. Write a program that prompts the user to enter a password and displays "Valid Password" if the rule is followed or "Invalid Password" otherwise. 16. * (Occurrences of a specified character) Write a function named “countChar” that finds the number of occurrences of a specified character in the string. For example, countChar("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string followed by a character and displays the number of occurrences of the character in the string. 17. **(Common prefix) Write a function that returns the common prefix of two strings. For example, the common prefix of "distance" and "disinfection" is "dis". If the two strings have no common prefix, the function returns an empty string. Write a main function that prompts the user to enter two strings and display their common prefix.
  • 5. LAB Performance 01: Write a program that 1) Take two numbers T and N as an input. T & N both are integers. T representthe test case.Foreach T 2) Find the divisors/factorsof N 3) For each test case print the case no and factors of the given number Sample Input: 3 6 4 2 Sample Output: Case 1: 1 2 3 6 Case 2: 1 2 4 Case 3: 1 2