0% found this document useful (0 votes)
10 views3 pages

Lab 6 B

Uploaded by

f23ari18
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)
10 views3 pages

Lab 6 B

Uploaded by

f23ari18
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/ 3

National University of Computer & Emerging Sciences (NUCES), Islamabad

Object Oriented Programming Spring – 2024


BS (CY)-B
Lab6
Recursion and Classes-II

Task-1
Write a recursive function in C++ that check if the given character array, which is passed in it is a
palindrome or not.

Function prototype is:

bool isPalindrome(char *start, char *end)// think cleverly about start and end pointers

Note: A character array is said to be palindrome if the reverse of the string is the same as the string.

Forexample ALPLA and KINGNIK are palindrome. TREE, FREE are not palindrome.

Task-2
Design an inventory class that can hold information and calculate data for items in a retail store’s
inventory. The class should have the following private member variables:

itemNumber //An int that holds the items’s item no


quantity // An int for holding the quantity of the items on hand
cost // A double for holding the wholesale per unit cost of the item
totalCost // A double for holding the total inventory cost of the item (calculated as quantity times
cost)

The class should have the following public member functions:

Parameterless Constructor // Sets all member variables to zero


Parametrized Constructor //Accepts an item no, cost and quantity as arguments. The function
//should assign these values to the appropriate member variables and
then call the setTotalCost function.

setItemNumber //Accept an integer argument that is copied to the itemNumber


member //variable

setQuantity //Accept an integer argument that is copied to the quantity member


variable
setCost // Accepts a Double argument that is copied to the cost member
variable
National University of Computer & Emerging Sciences (NUCES), Islamabad

setTotalCost //Calculate the total inventory cost for the item(quantity times cost)
and //stores the result in totalCost

getItemNumber // Returns the value in itemnumber


getQuantity //Returns the value in quantity
getCost //Returns the value in cost
getTotalCost //Returns the value in total cost

Demonstrate the class in a main() function.


Input Validation: Do not accept negative values for item member, quantity or cost.

Task-3
Define a class FlightInfo in C++ with following description:

Private Members
A data member FlightNumber of type integer
A data member Destination of type char*
A data member Distance of type float
A data member Fuel of type float

A member function void calFuel() to calculate the value of Fuel as per the following criteria and set its corresponding
data member
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200

Public Members
A function void feedInfo() to allow user to enter values for Flight Number, Destination, Distance & call function void
calFuel() to calculate the quantity of Fuel
A function void showInfo() to allow user to view the content of all the data members
A function float getFuel() that returns the current fuel value.

Task 4:
Write a Circle class that has the following private member variables:
Radius – a double
Pi – a double initialized with the value 3.1 4159
The class should have the following public member functions:
Default Constructor- user define default constructor that sets radius to 0.0
Constructor- user define constructor that accepts the radius of the circle as an argument
SetRadius- a mutator for the radius variable
getRadius- an accessor for radius variable
getArea- return the area of the circle which is calculated as
area= pi * radius * radius
getdiameter- returns the diameter of the circle which is calculated as
diameter= radius * 2
getCircumference- returns the circumference of the circle
circumference=2 * pi * radius
National University of Computer & Emerging Sciences (NUCES), Islamabad

Write a C++ program that demonstrate the Circle class by asking the user for the circle’s radius, creating a Circle
object,then reporting the circle’s area , diameter,and circumference.

Submission Guidelines :
 Do not zip your tasks, upload your tasks separately on GCR with naming convention:
TaskNumber_rollNumber.cpp

 Pledgerism will result in ZERO marks.

 No late submission will be mark.

You might also like