You are on page 1of 2

UNIVERSITY OF HARIPUR

Khyber Pakhtunkhwa, pakistan


2st Semester
Assignment # 03
SUBMITTED TO: MAM MISBAH SIKANDER
Year 2020

NAME ABEEHA ZAINAB


ROLL NO : S20-0154
SECTION ‘B’
SUBJECT OBJECT ORIENTED PROGRAMMING
DEPARTMENT INFORMATION TECHNOLOGY (IT)
Q1). Write a code to write and read multiple objects of a class to and from disk.

Hint: Use the uploaded slides for help.


WRITING CODE:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
char ch = 'x';
int j = 77;
double d = 6.25;
string s = "abeeha";
ofstream outfile("fdata.text");
outfile<< ch << j << d << s << endl;
cout<<"File written\n" ;
return 0;
}
Output

READING CODE:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
char ch ;
int j ;
double d;
string s;
ifstream infile("fdata.text");
infile>> ch >> j >> d >> s ;
cout<<"File Read\n" ;
return 0;
}

You might also like