Professional Documents
Culture Documents
Instructions:
Assignment Group
Assignment 1 18BCA1085 - 18BCA1102
Assignment 2 18BCA1103 - 18BCA1112
Assignment 3 18BCA1113 - 18BCA1125
Assignment 4 18BCA1126 - 18BCA1138
Assignment 5 18BCA1139 - 18BCA1154
Assignment 6 18BCA1156 - 18BCA 1195
Assignment 7 18BCA1201 - 18BCA3021 and
17BCA1489,1510,1571
S UIDs ASSIGNMENT-III
N GROUPIN
o. G
1 A 1) Write a function in C++ to count the number of vowels present in a text
file “NOTES.TXT”.
2) Write a function in C++ to print the count of word “the” as an
independent word in a text file “STORY.TXT”.
for example, if the content of the file “STORY.TXT” is
There was a monkey in the zoo. The monkey was very naughty.
Then the ouput of the program should be 2.
3) Assuming that a text file named FIRST.TXT contains some text written
into it, write a function named vowelwords(), that reads the file
FIRST.TXT and creates a new file named SECOND.TXT, to contain
only those words from the file FIRST.TXT which start with a lowercase
vowel (i.e., with 'a', 'e', 'i', 'o', 'u').
For example, if the file FIRST.TXT contains
Carry umbrella and overcoat when it rains
Then the file SECOND.TXT shall contain
umbrella and overcoat it
4) Write a program to print the address of a variable whose value is input
from user.
5) Write a program to print the address of the pointer to a variable whose
value is input from user.
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 not
starting with alphabet 'A' present in a text file "STORY.TXT".
Example:
If the file "STORY.TXT" contains the following lines,
The rose is red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
The function should display the output as 3.
3) Differentiate between compile-time and run-time polymorphism with
suitable programs.
4) Write a program to print the value of the address of the pointer to a
variable whose value is input from user.
5) Write a program to print a number which is entered from keyboard using
pointer.
#include <iostream>
using namespace std;
class stu
{
protected:
int rno;
public:
void get_no(int a)
{
rno = a;
}
void put_no(void)
{
}
};
class test:public stu
{
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>
using namespace 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>
using namespace std;
int main ()
{
char ch;
streambuf * p;
ofstream os ("test.txt");
pbuf = os.rdbuf();
do {
ch = cin.get();
p -> sputc(ch);
} while (ch != '.');
os.close();
return 0;
}
#include <iostream>
using namespace std;
class stu
{
protected:
int rno;
public:
void get_no(int a)
{
rno = a;
}
void put_no(void)
{
}
};
class test:public stu
{
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 read the data from binary file. And display the outp
ut on screen.