Review Quesions 5 12
Review Quesions 5 12
● Write a recursive function that takes a string and checks whether it is a palindrome or not.
A Palindrome is a string that can be read the same from left to right and from right to left.
Ex. racecar, anna , madam
● Write a program that takes an array and prints it in reverse order using pointers.
● Write a class box that has three private variables (width, length , height) and has the following
functions
-getWidth()
-getLength()
-getHeight()
-calcArea() → Calculates the surface area of the box
-calcVolume() → Calculate the volume of the box
● Write a Class date that has three private variables (Day, month, year)
And has the following functions:
-getDay()
-getMonth()
-getYear()
-countDownDays(int future_day, int future_month, int future_year){
// print the difference between the date of the class and the future date in days
}
-countDownHours(int future_day, int future_month, int future_year){
// print the difference between the date of the class and the future date in Hours
}
-countDownMonth(int future_day, int future_month, int future_year){
// print the difference between the date of the class and the future date in Months
}
struct MyBox
{
int length, breadth, height;
};
int main ()
{
MyBox B1 = {10, 15, 5}, B2, B3;
++B1.height;
dimension(B1);
B3 = B1;
++B3.length;
B3.breadth++;
dimension(B3);
B2 = B3;
B2.height += 5;
B2.length--;
dimension(B2);
return 0;
}
Declare a structure to represent a complex number (a number having a real part and imaginary
part). Write C++ functions to add, subtract, multiply and divide two complex numbers.
1. Write the definition for a class called Rectangle that has floating point data members
length and width. The class has the following member functions:
void setlength(float) to set the length data member
void setwidth(float) to set the width data member
float perimeter() to calculate and return the perimeter of the rectangle
float area() to calculate and return the area of the rectangle
void show() to display the length and width of the rectangle
int sameArea(Rectangle) that has one parameter of type Rectangle. sameArea returns 1
if the two Rectangles have the same area, and returns 0 if they don't.
A common place to buy candy is from a machine. The machine sells candies,
chips, gum, and cookies. You have been asked to write a program for this candy
machine.
The program should do the following:
1. Show the customer the different products sold by the candy machine.
2. Let the customer make the selection.
3. Show the customer the cost of the item selected.
4. Accept money from the customer.
5. Release the item.
The machine has two main components: a built-in cash register and several
dispensers to hold and release the products.
int main( )
{
int stack[ 3 ];
push(stack , 5 , 3 ) ;
push(stack , 10 , 3);
push (stack , 24 , 3) ;
push(stack , 12 , 3) ;
//Accessing the top element .
cout << ”The current top element in stack is “ << topElement( ) << endl;
//as stack is empty , now further popping will show underflow condition .
pop ( );
}
int main() {
queue newQueue;
newQueue.enqueue(3);
newQueue.enqueue(8);
newQueue.enqueue(15);
cout << "Top Element of the Queue: " << newQueue.front() << endl;
newQueue.deqeue();
cout << "Top Element of the Queue: " << newQueue.front() << endl;
return 0;
}
Write a function in C++ to count and display the number of lines not starting with
alphabet 'A' present in a text file "STORY.TXT".
Example:
If the file "STORY.TXT" contains the following lines,
The rose is red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
#include<iostream>
using namespace std;
int main() {
int x, n;
cout << "Enter the number of items:" << "\n";
cin >>n;
int *arr = new int(n);
cout << "Enter " << n << " items" << endl;
for (x = 0; x < n; x++) {
cin >> arr[x];
}
cout << "You entered: ";
for (x = 0; x < n; x++) {
cout << arr[x] << " ";
}
return 0;
}