Anda di halaman 1dari 10

Kulachi Hansraj Model School

Computer Science (083)


Class-XII
List of Programs (2010-11)

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

STRING Manipulation (Wt. 1)


3. Write program to accept a string and display the following menu with out using built-
in functions: -
o String Length.
o Palindrome or not.
o Vowel count
o Change case.

ARRAYS & FUNCTIONS(Wt. 2)


4. Given two arrays of integers A and B of sizes M and N respectively. Write a function
named MIX() which will produce a third array named C, such that the following
sequence is followed : (HOTS)
All even numbers of A from left to right are copied into C from left to right.
All odd numbers of A from left to right are copied into C from right to left
All even numbers of B from left to right are copied into C from left to right.
All odd numbers of B from left to right are copied into C from right to left
A, B and C are passed as arguments to MIX().
e.g. : A is {3,2,1,7,6,3} and B is {9,3,5,6,2,8,10}, the resultant array C is
{2,6,6,2,8,10,5,3,9,3,7,1,3}
5. Write a function in C++ which accepts an integer array and its size as arguments /
parameters and assign the elements into a two dimensional array of integers in the
following format (HOTS)
If the array is 1, 2,3,4,5,6 If the array is 1,2,3
The resultant 2D array is given below The resultant 2D array is
1 2 3 4 5 6 given below
1 2 3 4 5 0 1 2 3
1 2 3 4 0 0 1 2 0
1 2 3 0 0 0 1 0 0
1 2 0 0 0 0
1 0 0 0 0 0

CLASSES (Wt. 3+2+1)


6. Define following class and make menu driven program to call its functions.
class array
{ int a[10];
int n;
public:
void createarray();
void showarray();
void insertion_Sort();
void selectsort();
void bubble_sort();
void Binary_search();
void Linear_search();
};

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)

13. Consider the following structure


struct STUD
{
int Rno;
char Name[20];
};
Write the program which displays the following menu and allows following file operations
(assuming the binary file is containing the objects of the above mentioned structure) -
• Create New file
• Display all records
• Display record of particular roll no. if present (Search)
• Exit
NOTE : Define separate functions for above mentioned operations

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

STACKS and QUEUE (Wt. 4)


15. Consider the following class declaration :
class s_stack
{ int s[10];
int size;
int top;
public:
void push();
int pop();
void show_stack();
s_stack(); // Constructor Function
};
Write a program in C++ to define above mentioned class, show the menu as follows and do
the appropriate programming :

************* Operations on STACK ***************


1. PUSH
2. POP
3. DISPLAY STACK
4. EXIT

16. consider the following class declaration :


class c_queue
{ int q[10];
int size;
int F,R; // for Front index and Rear index
public:
void Add_Q();
int del_Q();
void show_Q();
c_queue(); // Constructor Function
};
Write a program in C++ to define above mentioned class, show the menu as follows and do
the appropriate programming :

************* Operations on QUEUE ***************


o ADDQ
o DELQ
o DISPLAY QUEUE
o 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;
}

testmeout(int n, char *n) //Function 3


{ rollno=n;
strcpy(name,n);
cout<<name<<” is in examination hall”<<endl;
cout <<”His Roll No. is “<<rollno<<endl;
}

testmeout(testmeout & t) //function 4


{
rollno = t.rollno;
strcpy(name,t.name);
}
void mywork() //Function 5
{ cout<<rollno<<” is attempting questions “<<endl;
}
};
void main()
{ testmeout ob1;
ob1.mywork();
testmeout ob2(5,”SAM”);
ob2.mywork();
testmeout ob3(ob2);
ob3.mywork();
}
i) In object oriented programming, what is Function 1 referred as and when does it get invoked?
ii) In object oriented programming, what is Function 2 referred as and when does it get invoked?
iii)In object oriented programming, what is Function 3 referred as and when does it get invoked?
iv) What will be the output of the above code ?
OUTPUT
POINTERS
Q.3 Find the output of the following program (pointer1.cpp)
#include<iostream.h>
#include<conio.h>
#include<string.h>
class state
{ char *statename;
int size;
public:
state(){size=0;statename=new char[size+1];}
state (char *s)
{ size=strlen(s);statename=new char[size+1];
strcpy(statename,s);
}
void display()
{ cout<<statename<<endl;}
void replace(state&a, state &b)
{size=a.size+b.size;
delete statename;
statename=new char[size+1];
strcpy(statename, a.statename);
strcat(statename,b.statename);
}
};
void main()
{ clrscr();
char *temp="Delhi";
state state1(temp), state2("Mumbai"), state3("Nagpur"), s1,s2;
s1.replace(state1,state2);
s2.replace(s1,state3);
s1.display();
s2.display();
getch();
}
OUTPUT

Anda mungkin juga menyukai