oops 4
oops 4
Aim:- Write a program to perform the deletion of whitespaces such as horizontal tabs,
vertical tabs, space, line feed, new line and carriage return from a text file and store the
contents of the file without the white spaceson another file.
Program :-
#include <iostream>
#include<fstream>
using namespace std;
int main(){
ifstream prev("according_8_1.txt"); ofstream next("according_8_2.txt"); char ch;
int c = prev.peek(); while(!prev.eof())
{
ch= prev.get();
if(ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\f' || ch == '\v'||ch=='\0'){} else{
next.put(ch);
}
c = prev.peek();
}
cout << "Program Executed" << endl; return 0;
}
Program-23
Aim:- Write a program to read the class object of student_info such as name, age, sex, height
and weight from the keyboard and to store them on a specified file using read() and write()
functions. Again, the same file is opened for reading and displaying the contents of the file on
the screen.
Program :-
#include <iostream>
#include <fstream>
using namespace std;
void student_info :: read(){ cout << "Enter Name: "; cin >> name;
cout << "Enter Age: "; cin >> age;
cout << "Enter Gender(F/M): "; cin >> sex;
cout << "Enter Height: "; cin >> height;
cout << "Enter Weight(kilogram): "; cin >> weight;
}
int main(){
int n;
cout << "Enter how many records are to be stored: "; cin >> n;
student_info student[n]; ofstream output;
output.open("according_9.txt", ios::app);
// output.write()
for (int i = 0; i < n; i++){ student[i].read();
// output.write(student, sizeof(student[i])); output << student[i].write();
}
output.close(); ifstream fin;
cout << "..............DISPLAYING THE CONTENTS OF THE FILE. " << endl;
fin.open("according_9.txt"); string input;
for(int i = 0; i < n; i++){ while(getline(fin, input)){
cout << input << endl;
}
}
fin.close(); return 0;
}
Program-24
Aim:- Write a program to raise an exception if any attempt is made to refer an element
whose index is beyond the array size.
Program :-
#include <iostream>
using namespace std;
cout << "Do you want to get any other element(y/n): "; cin >> choice;
if(choice == 'n'){ running = false;
}
else if(choice != 'y' && choice != 'n'){ cout << "Wrong choice entered!\n";
}
}
return 0;
}
Program-25
Aim:- Write a program to read a set of lines from the keyboard and to store it on a
specified file.
Program :-
#include <iostream>
#include <fstream>
using namespace std;
Aim:- Write a program to read a text file and display its contents on the screen
Program :-
#include <iostream>
#include <fstream>
using namespace std;
Program :-
#include <iostream>
#include <fstream>
using namespace std;
Aim:- Write a program to read two numbers and divide the first number by the second
number and raise anexception if the second number is zero.
Program :-
#include <iostream>
using namespace std;