SERIES (Wt. 1)
1. Write a function to generate the following series using functions passing the
required parameters:-
a. 1 + x2/2! + x3/3!.........xn/n!
b. 1+x2/3!-x3/4!.........xn/n+1!
MACROS(Wt. 1)
2. Write a program to define following macro/constant and their implementation:
• Area of rectangle
• Area of square
• Area of triangle
• Constant Max = 100
7. Define following class and make menu driven program for doing various operations:
class arr2d
{ int a[10][10];
int m,n;
public;
void create2D( );
void show2D( );
void show2D_LOWER1( );
void show2D_LOWER2( );
void show2D_UPPER1( );
void show2D_UPPER2( );
void show_Diagonal1( );
void show_Diagonal2( );
};
Assuming the2D array to be a square matrix with odd dimensions , i.e 3x3, 5x5,7x7, etc
Example if the array content is
543
678
129
Output through the function void show_Diagonal1( ) and void show_Diagonal2( )
should be
Diagonal one : 5 7 9
Diagonal two : 3 7 1 .
Output through the function void show2D_LOWER1( ) and show2D_LOWER2( ) should be
5 3
67 7 8
129 1 2 9
Output through the function void show2D_UPPER1( ) and show2D_UPPER2( ) should be
543 543
78 67
9 1
8. Consider the following class employee
Private members:
Data members
EmpNo Integer
Name Character
Address Character
Pin code Character
Basic Salary Float
HRA Rate Float
DA Rate Float
PF Rate Float
HRA Float
DA Float
PF Float
GROSS Float
NET Float
• Calculate() to calculate HRA, DA, PF, GROSS and net salary
Public:
• Retempno() function to return empno
• Retename() function to return employee name
• Readdata() to accept employee no, name, address, pincode, Basic salary, HRA
rate, DA rate and PF rate.
Invoke function calculate() to calculate HRA, DA, PF, GROSS and net salary
• Displaydata() to display employee no, name, address, pincode, Basic salary, HRA,
DA, PF, GROSS and net salary of the employee
Display the following menu for atleast 5 employees (Array of employee type): -
o Create. To accept data of 5 employee
o Salary statement. To display payslip of 5 employee
o Query in employee number. To accept empno and display relevant data
o Query on employee name. To accept employee name and display relevant
data.
INHERITANCE(Wt. 1)
9. Consider the classes:
class student{
protected:
int roll;
char name[10];
public:
void read_roll();
void show_roll();
int return_roll()
{
return roll;
}
};
class test:public student
{
protected:
float unit1, unit2;
public:
void get_marks();
void show_marks();
};
class sports
{ protected:
char grade;
public:
void get_grade();
void show_grade();
};
class result : public test , public sports
{ float total;
public:
void show_result();
};
Complete the definition of above mentioned classes and write main function for
processing result of 5 students (array of result) and display a menu:
1. Create (array of 5 result)
2. show result of all
3. Search on the basis of roll no. and display result if roll no found
4. Exit
FILE HANDLING (Wt. 5)
10. Write a program to accept a text file name and display: -
• Number of characters
• Frequency Table
o No of Uppercase character
o No of Vowels
o No of Digits
o No of Words (considering words are separated by a space)
o Number of lines
11. Write a program to accept the text file name and do the following (Use modular
approach, use seekg(), seekp(), tellg() , tellp() functions as required for the same)-
Encode file (by replacing every character with its subsequent character)
Decode file (back to original contents)
12. Write a program to accept a source file name and target file name and display the
following menu: -
Copy contents source to target
Change case of source to target
Replace many spaces to one space
(if words are separated by more than one space.
The function must return total no. of spaces removed)
14. Write a program to create an employee class having the following data members: -
Private
Emp_no Integer
Name Character
Basic Float
HRA Float
DA Float
PF Float
Public
Readata() To accept the data
Retempno() Function to return employee no.
Showdata() To show the data
And display the following menu: - NOTE : Define separate functions for operations
Create New file (with 5 records)
Add Record (in existing file)
Modify record of particular employee (Using one file)
Search (On the basis of Name)
Display All records
Exit
17. Write a program to perform various stack operations like push(), pop(), display() on a linked
stack having following node structure: - (Class approach)
struct Node
{
int roll;
int marks;
Node *link;
};
18. Write a program to perform various queue operations like Add(), del(), display() on a linked
queue having nodes with one integer and one floating type data. (Without Class)
struct Node
{
int x;
float y;
Node *link;
};
Test Your Knowledge
this POINTER
Try the following program illustrating the use of this pointer
#include <iostream.h>
#include <string.h>
#include <conio.h>
class person
{ char name[10];
int age;
public:
person(char *n , int a) // constructor function
{
strcpy(name, n);
age = a;
}
person & greater_age( person & x)
{
if (x.age > age)
return x;
else
return * this;
getch( );
}
void display()
{
cout <<"\nName : "<<name;
cout <<"\nAge : "<<age;
}
};
int main( )
{
person p1("Amit", 21), p2("Tom", 23), p3("john", 27);
person p=p1.greater_age(p3);
cout <<"\nElder person is :";
p.display();
p=p1.greater_age(p2);
cout <<"\nElder person is :";
p.display( );
}
OUTPUT
Constructor & Destructor Functions
#include <iostream.h> // Program name : constru.cpp
#include <string.h>
#include <conio.h>
Class testmeout
{ int rollno;
char name[20];
public:
~testmeout() //Function 1
{ cout<<rollno<<” is Leaving examination hall”<<endl;
cout <<”His Name is “<<name<<endl;
}
testmeout() //Function 2
{ rollno=1;
strcpy(name,”Amit”);
cout<<rollno<<” is appearing for examination “<<endl;
cout <<”His Name is “<<name<<endl;
}