Importent Question from UNIT-2 & UNIT-3
Importent Question from UNIT-2 & UNIT-3
DAY: 1
FIVE MARKS QUESTIONS
1. How to Define a class and object? Explain with syntax and example?
2. Explain Member function inside the class definition with syntax and example?
3. Explain Member function outside the class definition with syntax and example?
4. Explain Array of objects with example program?
(1) Student
Reg Name DoB Fees
101 Neha 02-Mar-2006 55000
i. Create a table for above given columns.
ii. Insert a row for given data in the table.
iii. Display the structure of a table.
iv. Alter the table by adding new column ‘Course’
v. Display all the records.
(2) Employee
ID Name DoJ Salary
2001 Kiran 04-Apr-1997 85000
i. Create a table for above given columns.
ii. Insert a row for given data in the table.
iii. Alter the table by adding new column ‘Department’
iv. Update the Name as ‘Karthik’ for id =2001;
v. Display all the records.
(3) Student
Roll No Name Sub1 Sub2 Sub3 Total Perc Result
101 Vidhya 80 95 65
102 Sara 70 86 56
103 Pavan 25 75 78
i. Create a table for above given columns.
ii. Insert a row for given data in the table (for 1 Record).
iii. Alter the table by adding new columns such as Total, Perc, Result
iv. Calculate Total and Perc
v. Find Results if all Subjects marks is >=35 as ‘Pass’ and <35 as ‘Fail’.
(4) Student
Reg No Name Marks
S1 ABC 90
i. Create a table on Student with Columns Reg No, Name, Marks
ii. Insert One Record (S1, ABC, 90)
iii. Recalculate the marks by adding 5 marks to the Student’s marks
iv. Display the structure of the table.
v. Display the records.
1. get():
Syntax: ifstream_object.get(ch);
Example: char ch=’a’;
ifstream fin(“text.dat”);
fin.get(ch);
2. put():
Syntax: ofstream_object.put(ch);
Example: char ch=’a’;
ofstream fout(“text.dat”);
fout.put(ch);
3. getline():
Syntax: fin.getline(buffer,SIZE);
Example: char book[SIZE];
fstream fin;
fin.getline(book,SIZE);
4. read():
Syntax: ifstream_object.read((char *) &variable,sizeof(variable));
Example: student s;
ifstream fin(“text.dat”,ios::binary);
fin.read((char *) &s,size(s));
4. write():
Syntax: ofstream_object.write((char *) &variable,sizeof(variable));
Example: student s;
ofstream fout(“text.dat”,ios::binary);
fout.write((char *) &s,size(s));