Vous êtes sur la page 1sur 11

# Updated on : 18/5/12 Lab Activity Q1)

Record book program list for session 2012 13 1) CONCEPT IMPLEMENTATION : 2 D ARRAY MANIPULATION USING A CLASS Write a menu driven program to perform the following on an integer matrix of size 3x3 . class numbers { int x ; public : void input(void ); void display(void ) ; //array and its transpose . void rowcol(void); wise total . void uplow(void)) ; int maxleft (void); diagonal . int minright (void) ; diagonal . // to enter values into the array // to be called by input() , which displays the existing // to compute and display Row wise total and Column // to print upper triangle and lower triangle // to find and return the maximum value along the left // to find and return the minimum value along the right

int sumleftright(void) ; // to find and return the sum of left and right diagonal elements . void swaparr(void); // to swap the first row elements with the last row elements }; All member functions should be called from the main pgm . 2) CONCEPT IMPLEMENTATION : BASIC OOPs CONCEPT -Data hiding, Data Encapsulation, Array of objects . Define a class Travel in C++ with the description given below: Private Members: T_Code of type string No_of_Adults of type integer No_of_Children of type integer Distance of type integer TotalFare of type float Public Members: A constructor to assign initial values as follows: T_Code with the word NULL No_of_Adults as 0 No_of_Children as 0 Distance as 0 TotalFare as 0 A function AssignFare() which calculates and assigns the value of the data member TotalFare as follows: For each Adult Fare(Rs) For Distance(Km) 500 >=1000 300 <1000 & >=500 200 <500 For each Child the above Fare will be 50% of the Fare mentioned in the above table. For e.g., If Distance is 750,No_of_Adults=3 and No_of_Children=2 Then TotalFare should be calculated as No_of_Adults*300+No_of_Children*150 i.e. 3*300+2*150=1200 A function EnterTravel() to input the values of the data members T_Code,No_of_Adults,No_of_Children and Distance; and invoke the AssignFare() function. A function ShowTravel() which displays the content of all the data members for a Travel. Write a program to implement the above case study .Use array of objects . Allow user to enter no. of elements required for the array at run time. 3) CONCEPT IMPLEMENTATION : CONSTRUCTOR OVERLOADING , TYPES OF CONSTRUCTORS , DESTRUCTOR , ARRAY OF OBJECTS Write a program : A) to initialize an i) ii) iii) Object Akbar using default constructor Object Birbal using parameterized constructor Object Chanakya using Object Birbal using copy constructor

B) to display all data members of the instances Akbar ,Birbal, Chanakya . C) to implement destructors for the objects created . The class definition is as follows : class bank { long int prin; int noyrs ; float rate,si,amt ; public : float computeSI(); void showdata() ; }; 4) Concept Implementation : Bubble sort technique ,array of objects , passing and returning objects from functions Define a class Garments in C++ with the following descriptions: Private Members: GCode of type string GType of type string GSize of type integer GFabric of type string A function Assign( ) which calculates and assigns the value of GPrice as follows For the value of GFabric as COTTON, GType GPrice(Rs) TROUSER 1300 SHIRT 1100 For GFabric other than COTTON the above mentioned GPrice gets reduced by 10%. Public Members: GPrice of type float

A constructor to assign initial values of GCode, GType and GFabric with the word NOT ALLOTTED and GSize and GPrice with 0 A member function Input( ) to input the values of the data members GCode, GType, GSize and GFabric and invoke the Assign( ) function. A member function Display( ) which displays the content of all the data members for a Garment. A non member function SortNcostly() should receive the array of objects as parameter , sort the array in the ascending order of Gprice and display a consolidated list of garment details (use setw() , Bubble sort algorithm ) . The function should return the object , which holds the details of the most expensive garment . Functions to be invoked from the main program : Input() , Display(), SortNcostly Object : Garments clothes ;
Sorting using bubble sort....... for(i=0;i<n-1;i++)

## { for(j=0;j<n-1;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } }

5) CONCEPT IMPLEMENTATION : Writing structures to an array , initiating enquiry using binary search algorithm and fn returning structure. Implementation of Selection sort algorithm . Structure description : struct Applicant { char A_Rno; char A_Name; int A_Score; }; void Enrol() void Status() Applicant Findperson()

//Roll number of applicant //Name of applicant //Score of applicant // fn for user input // fn for display // fn for searching and then returning that // applicant record .

Write a program in C++ that would store n records to an array . Sort the array in the increasing order of A_Rno , using Selection Sort algorithm . The program should search for the rollnumber entered by the user , using binary search algorithm. The details of that student should then be displayed in a neat format .
SELECTION SORT (Pgm) for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } }

6) CONCEPT IMPLEMENTATION :MULTILEVEL INHERITANCE USING PUBLIC DERIVATION, ABSTRACT CLASS AND CONCRETE CLASS Write a program to read the data of a student using the following classes . Display details of the game played by him , alongwith personal data using the following class definitions . Give outside class definition for all member functions . Class description is as follows :

Class person Private : Char name,int age Public : read_per_data() , show_per_data() Class student Private : int roll , mks, char grade Public : read_stu__data() , char compute_grade() [to be called by read_stu-data()] , show_stu_data() Class game Private : char gm Public : read_gm_data() , show_gm_data() person --> student game The grade shall be calculated as follows : Mks 320 > 240.319 200.239 <199 Grade A B C D

Write objects of class game to a binary file (as many times the user wants) and display the contents in a neat interactive format . Note : read_gm_data() should invoke read_stu_data() and this in turn should invoke read_per_data() . Display functions also should be displayed in the same order .

7)CONCEPT IMPLEMENTATION : BINARY FILE HANDLING USING CLASS. Create a binary file PHONE.DAT, containing records of the following class definition . class Phonlist { char Name; char Address; char AreaCode; char PhoneNo; public: void Register(); // for input of data members void Show(); // for display of data members int CheckCode(char AC[]) { return strcmp(AreaCode,AC); } char * GetArCode( ) { return AreaCode ; } // to be called //by Show() }; Write a function TRANSFER( ) in C++, that would copy all those records which are having AreaCode as DEL from PHONE.DAT to PHONBACK.DAT. Display the contents of both the data files in a neat consolidated format . 8) Concept implementation : Insertion sort , Merge sort Algorithm using arrays and binary files class student { public : int admno ; char name ; void getdata() {cin >> admno >> name ; } void dispdata() {cout << admno << name ; } } XIIA,XIIB, CLASSXII ; Sort array XIIA and XIIB in ascending order of admno using Insertion sort algorithm. Write the function definition of mergesort() to merge the contents of two sorted arrays XIIA and XIIB into third array CLASSXII using Mergesort algorithm . The resultant array CLASSXII is required to be in ascending order of admno .

## Write a complete C++ program to implement the same .

INSERTION SORT // insertion sort begins float small ; int pos ; small = a ; for (i = 0 ; i < n ; i++) { if ( a[i] < small) {

small = a[i] ; pos = i ; } } float temp ; temp = a; /* swap position of smallest no. and a */ a = small ; a[pos] = temp ; float ptr ; for(int k = 1 ; k < n ; k++) { temp = a[k]; ptr = k - 1 ; while ( temp < a[ptr]) { a[ptr + 1 ] = a[ptr]; ptr = ptr - 1 ; } a[ptr + 1] = temp ; } /* sorting starts */

Mergesort.. void mergesort(int A[ ],int B[ ],int C[ ],int N,int M, int &K) ; void main() { clrscr(); int A[] = {1,3,5}; int B[] = {2,4,6,8}; int C; int N = 3; int M = 4 ; int K1; mergesort (A,B,C,N,M,K1); getch(); } void mergesort(int A[ ],int B[ ],int C[ ],int N,int M, int &K) { int I=0,J=0; K=0; while (I<N && J<M) if (A[I]<B[J]) C[K++]=A[I++]; else if (A[I]>B[J]) C[K++]=B[J++]; else { C[K++]=A[I++]; J++; } for (;I<N;I++) C[K++]=A[I]; for (;J<M;J++) C[K++]=B[J]; cout <<"\nThe contents of array A : " ; for (I = 0 ; I < 3 ; I++) cout <<A[I]<<'\t' ;

cout <<"\n\nThe contents of array B : " ; for (I = 0 ; I < 4 ; I++) cout <<B[I]<<'\t' ; cout <<"\n\nThe contents of array C : " ; for (I = 0 ; I < 7 ; I++) cout <<C[I]<<'\t' ; }

9) Concept implementation : Adding , deleting and displaying records using binary file handling with class . To accept as many objects the user wants of the following class type and write them to a data file MEMP.DAT . class employee // Class declaration { char name; float salary; public : int code; // Private data members // Public member functions void input() ; // fn to accept values for data members void show() ; // fn to display values of data members float retsal() ; // fn to return salary }; 1. 2. 3. 4. 5. Menu Add a record Delete a record Display record (all) Display record (filtered) Exit

Additional info : Option 2 : Delete record of users choice . Option 3 : Display all records Option 4 : Display details of those records whose salary is between 10000 and 20000. 10) CONCEPT IMPLEMENTATION : Writing text to a text file and then performing text manipulation operations on it . Write a menu driven program using separate functions for the following : 1. Create a text file to store upper case strings (FILEORIG.TXT) 2. Display the file (FILEORIG.TXT) 3. Convert text file (FILEORIG.TXT) to lowercase (FILELOW.TXT) 4. Display the lower case file (FILELOW.TXT) 5. To count the number of alphabets present in the text file FILELOW.TXT 6. To count the number of lines present in the text file FILEORIG.TXT. 7. To count and display the number of lines starting with alphabet A present in a text file FILEORIG.TXT. 8. To count the occurrences of the word "the" in the file "FILEORIG.TXT" 9. To encrypt the file , FILEORIG.TXT , by adding 25 to the ASCII value of each character read from file. Store the encrypted data into a text file MYENCRPYT.TXT . Decrypt this file and write to MYDECRYPT.TXT . Display the contents of the files :FILEORIG.TXT , MYENCRYPT.TXT and MYDECRYPT.TXT .

11) CONCEPT IMPLEMENTATION : Random access file handling Write a program to perform random access on a disk file , the structure definition of which is given below : (wl be mailed and student to take printout ) struct VEHICLE { char Vehicle_Code; char Vehicle_Name; float cost; }; The Menu should have the following options : Main Menu 1. Add Record 2. Display Record 3. Update Record 4. Exit Functions append() , display() and update() should perform the above tasks . 12) Concept implementation : Enquiry on binary file handling . (wl be mailed and student to take printout ) Write a program to write the name of the states and respective chief ministers to a disk file . Enable search by State or by CM from the disk file . class LIST { char States, CM; public: void GETIT() ; // fn to accept values for data members void SHOWIT( ) ; // fn to display values of data members int s1(char t_state) ; // fn to compare & locate state and // invoke fn showit() . int s2(char t_cop) ; // fn to compare & locate chief minister // and invoke fn showit() . }; The program should be menu driven MENU 1. Data Entry Module 2. Display all 3. Search by State 4. Search by CM"; 5. Exit Enter your choice : 13)Concept implementation : Merging binary files . (wl be mailed and student to take printout ) Write a program to merge two binary files (OLD.DAT and OLD1.dat) and create and display merged file (NEW.DAT) . The structure description is given below : struct employee { char name;

int empno; char status; float payrate; }; 14) Concept implementation : Application of dynamic array and linked list application . Write a menu driven program to : 1) Function name : fnarr() Create a dynamic two dimensional array , where the dimensions are accepted at runtime Accept values into the array and display its transpose . 2) Function name : fnobptr() struct employee { int empno; char name; float basic ; float experience; employee * link ; // self referential structure }; Create a dynamic linked list to store the above structure . Traverse the array and identify the person with maximum experience . In order to display all the details of the most experienced person , pass this structure to function display whose prototype is as follows : void display (employee *emp) ;

3) Exit

15) Concept Implementation : Application of linear search on a linked list . Write a C++ program to : a. Store user data into a linked list . Get user input of code for querying . b. Search (Linear search) for an employee in a linked list and display all details of that employee in a neat format . Display suitable message if employee does not exist . struct emp { char name; int code ; emp * next ; // self referential structure }; 16)Concept Implementation : Application of Linked stack Write a menu driven program to illustrate A LINKED STACK , on a dynamically allocated linked Stack where each node contains the name and age . LINKED STACK MENU 1) 2) 3) 4) PUSH TO STACK POP FROM STACK DISPLAY STACK EXIT

(wl be mailed and student to take printout ) 17) Concept Implementation : Application of Linked Queue

Write a menu driven program to illustrate A LINKED QUEUE , on a dynamically allocated linked QUEUE , where each node contains the account no. , account holders name and balance amount in his savings account . LINKED QUEUE MENU 1) 2) 3) 4) INSERT AN ELEMENT DELETE AN ELEMENT DISPLAY THE QUEUE EXIT

(wl be mailed and student to take printout ) 18) Concept Implementation : Implementation of stack using arrays . Write a program to implement an integer array stack to hold the marks of n students for Informatics Practices . The program should be menu driven and should facilitate pushing , popping and display of elements in the array stack . (wl be mailed and student to take printout ) 19) Concept Implementation : Implementation of queues using arrays . Write a program to implement an integer array queue to hold the marks of n students for Computer Science . The program should be menu driven and should facilitate addition , deletion and display of elements in the array queue . (wl be mailed and student to take printout )

20 ) Concept Implementation : Implementation of Circular Queue using array . Write a program using functions in C++ , to perform insert and delete operations on a circular queue using array . (wl be mailed and student to take printout ) 21) SQL documentation . Attach Qn. Paper followed by Query Result sheet .