0% found this document useful (0 votes)
13 views6 pages

Lab 1

The document outlines a lab session for an Object Oriented Programming course at UCP Lahore, focusing on revising C++ concepts such as loops, arrays, and functions. It includes objectives, instructions for coding, sample tasks with solutions, and specific lab tasks for students to complete. The tasks involve writing functions to perform various operations, such as calculating factorials, sorting arrays, and manipulating strings.

Uploaded by

hirrah21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Lab 1

The document outlines a lab session for an Object Oriented Programming course at UCP Lahore, focusing on revising C++ concepts such as loops, arrays, and functions. It includes objectives, instructions for coding, sample tasks with solutions, and specific lab tasks for students to complete. The tasks involve writing functions to perform various operations, such as calculating factorials, sorting arrays, and manipulating strings.

Uploaded by

hirrah21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Object Oriented Programming

Section O6

Session: fall 2022


Faculty of Information Technology
UCP Lahore, Pakistan
Table of Contents
Session: fall 2022 .................................................................................................................................... 1
Lab 1: Revision Lab .................................................................................................................................. 3
Lab Objective: ......................................................................................................................................... 3
Instructions: ........................................................................................................................................... 3
Sample task: ............................................................................................................................................ 4
Sample solution: ..................................................................................................................................... 4
Lab Tasks: ................................................................................................................................................ 5
Task 1: ............................................................................................................................................... 5
Task 2: ............................................................................................................................................... 5
Task 3: ............................................................................................................................................... 6
Task 4: ............................................................................................................................................... 6
Task 5: ............................................................................................................................................... 6
Task 6: ............................................................................................................................................... 6
Lab 1: Revision Lab

Lab Objective:
The basic purpose of this laboratory is revision of some preliminary concepts of c++ that has been
covered in the course of Introduction to Computing and Programming Fundamentals. Its objective is
to:

 Recall student’s previously learned basic concepts.


 Revision of loops, arrays and functions.
 Understanding problem statements and designing an appropriate solution.

Instructions:

 Indent your code


 Comment your code
 Use meaningful variable names
 Plan your code carefully on a piece of paper before you implement it.
 Name of the program should be same as the task name. i.e. the first program should be
Task_1_01.cpp
Sample task:
Write a function that find the factorial of a given number
Input:
6
Output:
Factorial of 6 is 720

Sample solution:

#include <iostream>
using namespace std;
int find_factorial(int num)
{
int fact = 1;
while (num > 1)
{
fact = fact*num;
num--;
}
return fact;
}
int main()
{
int num;
cout << "Enter a number to find factorial: ";
cin >> num;
if (num >= 0)
{
cout << "Factorial of " << num << " is: " << find_factorial(num) <<
endl;
}
else
{
cout << "Please enter a positive number!\n";
}
}
Lab Tasks:

Task 1:

Write a function that asks the user to enter a number N by showing the message “How many
numbers you want to enter”. After that the user will input N integer numbers one by one. From
those input numbers, place only the EVEN numbers in an array. Ask the User if he wants to enter
more numbers, if user says yes, repeat the above process until the user is interested to enter more
numbers. In the end it will tell how many time it press y (hint: static variable)

Task 2:

Write a program to sort the given ARRAY [98.7, 65.8, 11.9, 9.5, 67.9, 90.5, 90.9, 15.8, 16.9,
98.7] in ascending order using selection sort, print the output after each iteration till final
output. Also, print the repeated element.
Task 3:

Write a function that prints the multiples of nth number in an integer array
Input:
1,4,10,15,12,24,25,6,8,70
n=5
Output:
10,15,25,70

Task 4:

Write a function Array_Max_Index which takes an array of integers and its size as
parameters and returns the index of the largest integer in the array.

Task 5:

Write a function Array_Copy which takes two char arrays as input and copies all the
elements of the first array into the second.

Task 6:

Write a function Convert_To_Uppercase that takes a valid English sentence and


converts all of its letters to uppercase (Hint: Use a character array to store the sentence.
You can also add checks for invalid characters
ASCII of A is 65 and ASCII of a is 97).

You might also like