SlideShare a Scribd company logo
1 of 5
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

Year 2 dsa c++ exercises on user defined functions
Year 2 dsa  c++ exercises on user defined functionsYear 2 dsa  c++ exercises on user defined functions
Year 2 dsa c++ exercises on user defined functions
ErnesteNtezirizaza
 

What's hot (20)

Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMCLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
 
Operators
OperatorsOperators
Operators
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
SPL 12.1 | Multi Dimensional(Two) Array Practice Problems
SPL 12.1 | Multi Dimensional(Two) Array Practice ProblemsSPL 12.1 | Multi Dimensional(Two) Array Practice Problems
SPL 12.1 | Multi Dimensional(Two) Array Practice Problems
 
Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions
 
Basic concepts of python
Basic concepts of pythonBasic concepts of python
Basic concepts of python
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 
Year 2 dsa c++ exercises on user defined functions
Year 2 dsa  c++ exercises on user defined functionsYear 2 dsa  c++ exercises on user defined functions
Year 2 dsa c++ exercises on user defined functions
 
CP Handout#8
CP Handout#8CP Handout#8
CP Handout#8
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
 
Java programlist (1)
Java programlist (1)Java programlist (1)
Java programlist (1)
 
3. user input and some basic problem
3. user input and some basic problem3. user input and some basic problem
3. user input and some basic problem
 

Similar to Oop lab assignment 01

OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
gerardkortney
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
sjskjd709707
 
CSCI1250 Project 3 Fall 2015 CSCI1250 INTRODUCTIO.docx
CSCI1250    Project 3  Fall 2015  CSCI1250 INTRODUCTIO.docxCSCI1250    Project 3  Fall 2015  CSCI1250 INTRODUCTIO.docx
CSCI1250 Project 3 Fall 2015 CSCI1250 INTRODUCTIO.docx
faithxdunce63732
 
Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6
helpido9
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
comp274
 
Statement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docxStatement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docx
whitneyleman54422
 

Similar to Oop lab assignment 01 (20)

Java Practice Set
Java Practice SetJava Practice Set
Java Practice Set
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation file
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
CSCI1250 Project 3 Fall 2015 CSCI1250 INTRODUCTIO.docx
CSCI1250    Project 3  Fall 2015  CSCI1250 INTRODUCTIO.docxCSCI1250    Project 3  Fall 2015  CSCI1250 INTRODUCTIO.docx
CSCI1250 Project 3 Fall 2015 CSCI1250 INTRODUCTIO.docx
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
A01
A01A01
A01
 
Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Md university cmis 102 week 5 hands
Md university cmis 102 week 5 handsMd university cmis 102 week 5 hands
Md university cmis 102 week 5 hands
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 
Statement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docxStatement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docx
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Recently uploaded (20)

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 

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