SlideShare a Scribd company logo
RWANDA CODING ACADEMY
Module: Data Structures and algorithms with C++
Exercises
Using C++ solve the following using your own functions.
1. ​ Write a C++ program that will display the calculator menu.
The program will prompt the user to choose the operation choice (from
1 to 5). Each choice represents a function which returns the respective
operation. Then it asks the user to input two integer values for the
calculation. See the sample below.
MENU
1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus
Enter your choice: 1
Enter your two numbers: 12 15
Result: 27
Continue? y
The program also asks the user to decide whether he/she wants to
continue the operation. If he/she input ‘y’, the program will prompt the
user to choose the operation again. Otherwise, the program will
terminate.
2. Write a program in C++ with a function(void) to print the sum of two
numbers.
Example of the output :The sum of 29 and 30 is : 59
RWANDA CODING ACADEMY
3. ​Write a program in C++ with a function to add two numbers accepted
through the keyboard.
4. Write a program in C++ with a function(void) to swap two numbers.
Example of output
Input 1st number : 25
Input 2nd number : 39
After swapping the 1st number is : 39
After swapping the 2nd number is : 25
5. Write a program with a function that return the volume of the sphere.
6. ​Write a program in C++ with two functions to calculate the Area and
Perimeter of a Rectangle. You should get the width and length from the
user through the keyboard.
7. Using a function write a program in C++ to convert temperature in Celsius
to Fahrenheit.
Hints
How to convert Celsius temperatures to Fahrenheit
Multiply the Celsius temperature by 9/5.
Add 32​o​
to adjust for the offset in the Fahrenheit scale.
8. ​Write a program to compute quotient and remainder of two numbers
accepted from keyboard.
9. Write a program in C++ to check whether a number is positive, negative or
zero.
10. Write a C++ program to display the current date and time
11. Write a program in C++ which accepts the user's first and last name
and print them in reverse order with a space between them.
Sample output
RWANDA CODING ACADEMY
Input First Name: Mugisha
Input Last Name: Sam
Name in reverse is: Sam Mugisha
12. Write a program which accepts the radius of a circle from the user and
compute the area and circumference.
13. Write a program to compute the volume of the cube on user input.
14. Write a program to read three integeres and to print them in ascending
order
15. A program is required that checks strings to see if they are palindromes.
A palindrome string that reads the same, backwards, or forwards. For
example,
I was able no on elba saw I

More Related Content

What's hot (20)

PPT
Chapter 4 5
ahmed22dg
 
PDF
Fundamentals of nursing practice exa1
Nursing Path
 
PPT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
DOCX
C programming Lab 1
Zaibi Gondal
 
DOCX
Anatomy KMU Mcqs...2.docx
MuhammadRazaBuzdar
 
DOCX
C Programming
Rumman Ansari
 
DOC
Thay khanh iwaz
ChnhTrung3
 
PPTX
Functions
Golda Margret Sheeba J
 
PDF
COPA Practice Set (Previous Year Question Paper)
SONU HEETSON
 
PPT
Looping in C
Prabhu Govind
 
PPT
Function in C Language
programmings guru
 
PDF
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
PDF
Computer Mcqs.pdf
Nauman Malik
 
PPTX
Function C programming
Appili Vamsi Krishna
 
PPT
control-statements, control-statements, control statement
crrpavankumar
 
DOCX
C Programming
Sumant Diwakar
 
PDF
soft skills question paper set for bba ca
ohsadfeeling
 
PPT
Introduction to c programming
ABHISHEK fulwadhwa
 
PPTX
Switch case and looping statement
_jenica
 
Chapter 4 5
ahmed22dg
 
Fundamentals of nursing practice exa1
Nursing Path
 
CPU INPUT OUTPUT
Aditya Vaishampayan
 
C programming Lab 1
Zaibi Gondal
 
Anatomy KMU Mcqs...2.docx
MuhammadRazaBuzdar
 
C Programming
Rumman Ansari
 
Thay khanh iwaz
ChnhTrung3
 
COPA Practice Set (Previous Year Question Paper)
SONU HEETSON
 
Looping in C
Prabhu Govind
 
Function in C Language
programmings guru
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Computer Mcqs.pdf
Nauman Malik
 
Function C programming
Appili Vamsi Krishna
 
control-statements, control-statements, control statement
crrpavankumar
 
C Programming
Sumant Diwakar
 
soft skills question paper set for bba ca
ohsadfeeling
 
Introduction to c programming
ABHISHEK fulwadhwa
 
Switch case and looping statement
_jenica
 

Similar to Year 2 dsa c++ exercises on user defined functions (20)

DOC
project report in C++ programming and SQL
vikram mahendra
 
PPT
Apclass
geishaannealagos
 
PPT
Apclass (2)
geishaannealagos
 
PPT
Apclass (2)
geishaannealagos
 
DOCX
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
DOC
Project two c++ tutorial
Babatunde Salaam
 
PPT
Review chapter 1 2-3
ahmed22dg
 
DOC
Cs2312 OOPS LAB MANUAL
Prabhu D
 
DOC
programming in C++ report
vikram mahendra
 
PPT
Oop1
Vaibhav Bajaj
 
PDF
09 a1ec01 c programming and data structures
jntuworld
 
DOCX
B.Com 1year Lab programs
Prasadu Peddi
 
DOCX
C programs
vijaybandi36
 
PDF
Programming Practice Questions_C
Deep Prajapati Microplacer
 
PDF
C programming Assignments and Questions.pdf
rajd20284
 
PDF
Introduction to Basic C++ Program Examples .pdf
simegnew Ataley
 
PPTX
C++: An Introduction
Lucky Bwaromale Paul
 
PPTX
RECURSION.pptx
PrestonKhumbula1
 
PDF
1 borland c++ 5.02 by aramse
Aram SE
 
PDF
Data Structure.pdf
MemeMiner
 
project report in C++ programming and SQL
vikram mahendra
 
Apclass (2)
geishaannealagos
 
Apclass (2)
geishaannealagos
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
Project two c++ tutorial
Babatunde Salaam
 
Review chapter 1 2-3
ahmed22dg
 
Cs2312 OOPS LAB MANUAL
Prabhu D
 
programming in C++ report
vikram mahendra
 
09 a1ec01 c programming and data structures
jntuworld
 
B.Com 1year Lab programs
Prasadu Peddi
 
C programs
vijaybandi36
 
Programming Practice Questions_C
Deep Prajapati Microplacer
 
C programming Assignments and Questions.pdf
rajd20284
 
Introduction to Basic C++ Program Examples .pdf
simegnew Ataley
 
C++: An Introduction
Lucky Bwaromale Paul
 
RECURSION.pptx
PrestonKhumbula1
 
1 borland c++ 5.02 by aramse
Aram SE
 
Data Structure.pdf
MemeMiner
 
Ad

Recently uploaded (20)

PPTX
Day2 B2 Best.pptx
helenjenefa1
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Day2 B2 Best.pptx
helenjenefa1
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Ad

Year 2 dsa c++ exercises on user defined functions

  • 1. RWANDA CODING ACADEMY Module: Data Structures and algorithms with C++ Exercises Using C++ solve the following using your own functions. 1. ​ Write a C++ program that will display the calculator menu. The program will prompt the user to choose the operation choice (from 1 to 5). Each choice represents a function which returns the respective operation. Then it asks the user to input two integer values for the calculation. See the sample below. MENU 1. Add 2. Subtract 3. Multiply 4. Divide 5. Modulus Enter your choice: 1 Enter your two numbers: 12 15 Result: 27 Continue? y The program also asks the user to decide whether he/she wants to continue the operation. If he/she input ‘y’, the program will prompt the user to choose the operation again. Otherwise, the program will terminate. 2. Write a program in C++ with a function(void) to print the sum of two numbers. Example of the output :The sum of 29 and 30 is : 59
  • 2. RWANDA CODING ACADEMY 3. ​Write a program in C++ with a function to add two numbers accepted through the keyboard. 4. Write a program in C++ with a function(void) to swap two numbers. Example of output Input 1st number : 25 Input 2nd number : 39 After swapping the 1st number is : 39 After swapping the 2nd number is : 25 5. Write a program with a function that return the volume of the sphere. 6. ​Write a program in C++ with two functions to calculate the Area and Perimeter of a Rectangle. You should get the width and length from the user through the keyboard. 7. Using a function write a program in C++ to convert temperature in Celsius to Fahrenheit. Hints How to convert Celsius temperatures to Fahrenheit Multiply the Celsius temperature by 9/5. Add 32​o​ to adjust for the offset in the Fahrenheit scale. 8. ​Write a program to compute quotient and remainder of two numbers accepted from keyboard. 9. Write a program in C++ to check whether a number is positive, negative or zero. 10. Write a C++ program to display the current date and time 11. Write a program in C++ which accepts the user's first and last name and print them in reverse order with a space between them. Sample output
  • 3. RWANDA CODING ACADEMY Input First Name: Mugisha Input Last Name: Sam Name in reverse is: Sam Mugisha 12. Write a program which accepts the radius of a circle from the user and compute the area and circumference. 13. Write a program to compute the volume of the cube on user input. 14. Write a program to read three integeres and to print them in ascending order 15. A program is required that checks strings to see if they are palindromes. A palindrome string that reads the same, backwards, or forwards. For example, I was able no on elba saw I