/* Slip no : 19_1 Write a C++
program to create a class Integer. Write necessary member functions to overload
the operator unary pre and post decrement ‘--’ for an integer
number. */
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class integer
{
int
no;
public:
integer(){}
integer(int
num)
{
no=num;
}
integer
operator--()
{
--no;
return
*this;
}
integer
operator--(int) //post increment
{
integer
temp=*this;
no--;
return
temp;
}
void
display()
{
cout<<"\nNo
= "<<no;
}
};
void main()
{
integer
i(10),i1(10),i3;
clrscr();
cout<<"\nAfter
postdecrement : ";
i3=i--;
i3.display();
cout<<"\nAfter
predecrement : ";
i3=--i1;
i3.display();
getch();
}
/* Slip no : 19_2 Write a C++
program to read the contents of a Sample.txt” file. Store all the uppercase
characters in ”Upper.txt”, lowercase characters in ”Lower.txt” and digits in
“Digit.txt” files. Change the case of each character from “Sample.txt” and
store it in “Convert.txt” file.*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
#include<ctype.h>
void main()
{
char
fname[20];
ifstream
fin; ofstream fc,fu,fl,fd;
cout<<"\n
Enter file name : ";
cin>>fname;
fin.open(fname,ios::in);
fc.open("convert.txt",ios::out);
fu.open("upper.txt",ios::out);
fl.open("lower.txt",ios::out);
fd.open("digit.txt",ios::out);
if(fin.fail())
{
cout<<"file
not exists ";
exit(1);
}
char
ch;
while(!fin.eof())
{
ch=fin.get();
if(islower(ch))
{
fl.put(ch);
ch=toupper(ch);
fc.put(ch);
}
else
if(isupper(ch))
{
fu.put(ch);
ch=tolower(ch);
fc.put(ch);
}
else
if(isdigit(ch))
{
fd.put(ch);
}
else
if(isspace(ch))
{ fc.put(ch);
}
}
cout<<"file
coped....";
getch();
slips 19
Reviewed by Dinesh Varal
on
January 20, 2018
Rating:
No comments: