BSC/BCA-2 Object Oriented Programming (SCT-155/CAT-153) Assignment-3
BSC/BCA-2 Object Oriented Programming (SCT-155/CAT-153) Assignment-3
Instructions:
Groups UID’s
S UIDs ASSIGNMENT-III
No. GROUPING
1 A 1) Write a function in C++ to count the number of vowels present in a text file
“NOTES.TXT”.
2) What are pure virtual functions. Explain with a program. Differentiate between
virtual and pure virtual functions.
3) Write a C++ program to write number 100 to 150 in a data (.txt) file.
4) Write a program to print the address of a variable whose value is input from user.
5) Write a program to create a class named student which contains two member
functions getdata() and showdata() to get input from user(id, name, address,
marks in different subjects) and to display the entered data. Access the member
functions using pointer to objects.
2 B 1) Write a user defined function in C++ to read
the content from a text file
“MYbook.txt”, count and display the number of blank spaces present in it.
2) Write a function in C++ to count and display
the number of lines starting with alphabet 'A' present in a text file "STORY.TXT".
Example:
If the file "STORY.TXT" contains the following lines,
There is a playground.
A child is playing there.
A ball is in her/his hand.
Numbers are not allowed in the password.
The function should display the output as 2.
3) Differentiate between compile-time and run-
time polymorphism with suitable programs.
4) Write a program to declare a pointer to the base class and access the member
functions of base and derived class.
5) Write a program to print a number which is
entered from keyboard using pointer.
3 C 1) Write a function in C++ to count the number of alphabets present in a text file
“NEWFILE.TXT”.
2) Assuming that a text file named FIRST.TXT contains some text written into it,
write a function named copyupper(), that reads the file FIRST.TXT and creates a
new file named SECOND.TXT contains all words from the file FIRST.TXT in
uppercase.
3) Differentiate between virtual functions and pure virtual functions with suitable
programs.
4) Write a function which will take pointer and display the number on screen. Take
number from user and print it on screen using that function.
5) Write a program to find out the greatest and the smallest among three
numbers using pointers.
4 D 1) What is pointer arithmetic? Explain with doing addition and subtraction operation
on pointer variables.
2) Write a program that reads a file containing a list of numbers and writes two files,
one with all the numbers divisible by 3 and another containing all the other
numbers.
3) Illustrate the random accessing of text file with suitable program. Explain why it
is important as compared to sequential accessing.
4) Write a program to find the factorial of a number using pointers.
5) Write a program to reverse the digits a number using pointers.
5 E 1) Write a program to create a text file named “newfile.txt” with 5 lines and write a
function to count the number of lines present in this text file.
2) Design a file format to store a person's name, address, and other information.
Write a program to read this file.
3) Compile the below written code and find out the errors. After debugging give
the output of this program?
#include <iostream>
using namespace std;
class stu
{
protected:
int rno;
public:
void get_no(int a)
{
rno = a;
}
void put_no(void)
{
}
};
class test:publicstu
{
protected:
float part1,part2;
public:
void get_mark(float x, float y)
{
part1 = x;
part2 = y;
}
void put_marks()
{
}
};
class sports
{
protected:
float score;
public:
void getscore(float s)
{
score = s;
}
void putscore(void)
{
}
};
class result: public test, public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total = part1 + part2 + score;
put_no();
put_marks();
putscore();
cout<< "Total Score=" << total << "\n";
}
int main()
{
result stu;
stu.get_no(123);
stu.get_mark(27.5, 33.0);
stu.getscore(6.0);
stu.display();
return 0;
}
4) Consider the following code, find errors if any and write the correct code and
output:
#include <iostream>
usingnamespace std;
int main ()
{
char first, second;
cout<< "Enter a word: ";
first = cin.get();
cin.sync();
second = cin.get();
cout<< first <<endl;
cout<< second <<endl;
return 0;
}
5) Consider the following code, find errors if any and write the correct code and
output:
#include <iostream>
#include <fstream>
usingnamespace std;
int main ()
{
charch;
streambuf* p;
ofstreamos("test.txt");
pbuf=os.rdbuf();
do{
ch=cin.get();
p ->sputc(ch);
}while(ch!='.');
os.close();
return0;
}
6 F 1) Write a C++ program that update the contents in a text file.
2) Write a C++ program, which initializes a string variable to the content "Time is
a great teacher but unfortunately it kills all its pupils. Berlioz" and outputs the
string to the disk file OUT.TXT. You have to include all the header files if
required.
3) Demonstrate the use of abstract class in real-world programming and illustrate
how it is different from concrete class.
4) Write a program to read the data from text file. And display the output in another
file.
5) Write a program to write and read the data from text file. And display the output
on screen.
7 G 1) How updation is done in sequential file? Explain in detail with suitable
examples.
2) Differentiate between static and dynamic memory allocation.
3) Compile the below written code and find out the errors. After debugging given
the output of this program.
#include <iostream>
using namespace std;
class stu
{
protected:
int rno;
public:
void get_no(int a)
{
rno = a;
}
void put_no(void)
{
}
};
class test:publicstu
{
protected:
float part1,part2;
public:
void get_mark(float x, float y)
{
part1 = x;
part2 = y;
}
void put_marks()
{
}
};
class sports
{
protected:
float score;
public:
void getscore(float s)
{
score = s;
}
void putscore(void)
{
}
};
class result: public test, public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total = part1 + part2 + score;
put_no();
put_marks();
putscore();
cout<< "Total Score=" << total << "\n";
}
int main()
{
result stu;
stu.get_no(123);
stu.get_mark(27.5, 33.0);
stu.getscore(6.0);
stu.display();
return 0;
}
4) Write a program to read the data from binary file. And display the output in another
file.
5) Write a program to write and read the data from a binary file. And display the output
on screen.
Note- Groups will be as the previous assignments. Each group will have 5 students.