Professional Documents
Culture Documents
Muddywise Book
Muddywise Book
Page 1 of 1
ASSIGNMENT ON FILES.
#include <fstream>
#include <iostream>
int main()
ofstream outfile;
outfile.open(“.muddy.txt”);
int m,u,d;
m = 10;
u = 2;
d = u*d;
outfile << m;
outfile << u;
outfile << d;
outfile.close();
return 0;
RAM DIAGRAMS.
FREE
FREE
Page 2 of 2
FREE
FREE
FREE
FREE
FREE
RESERVED
RESERVED
outfile
RESERVED
RESERVED
RESERVED
RESERVED
10
2
20
outfile
10
2
20
Page 3 of 3
2. Example of input file code.
#include <fstream>
#include <iostream>
int main()
ifstream infile;
infile.open(“muddy.txt”);
int a, b, c;
infile >> a;
infile >> b;
infile >> c;
infile.close();
cout << a;
cout << b;
cout << c;
return 0;
RAM DIAGRAMS.
FREE
FREE
Page 4 of 4
FREE
FREE
FREE
FREE
FREE
RESERVED
RESERVED
RESERVED
infile
RESERVED
RESERVED
a RESERVED
10
2
Page 5 of 5
infile 20
10
2
a 20
Page 6 of 6
3. Functions of files
#include <fstream>
#include <iostream>
void output()
ofstream outfile;
outfile.open(“muddy.txt”);
int m,u,d;
m= 10;
u = 2;
d = m*u;
outfile << m;
outfile << u;
Page 7 of 7
outfile << d;
outfile.close();
void input()
ifstream infile;
infile.open(“muddy.txt”);
int a, b, c;
infile >> a;
infile >> b;
infile >> c;
infile.close();
cout << a;
cout << b;
cout << c;
int main()
void output();
void input();
output();
input();
return 0;
Page 8 of 8
}
#include <fstream>
#include <iostream>
int main()
ofstream outputfile;
outputfile.open(“Output.txt”);
if (outputfile.is_open()){
outputfile.close();
} else {
Page 9 of 9
return 0;
#include <fstream>
#include <iostream>
int main()
ifstream inputfile;
inputfile.open(“Output.txt”);
if (inputfile.is_open()){
int array[3][1];
cout << “Array after multiplying each element by 4:” << endl;
Page 10 of 10
}
inputfile.close();
} else {
return 0;
ASSIGNMENT ON POINTRES.
//Pointers variables
#include <iostream>
int main()
int i = 15;
int *p1;
int *p2;
p1 = &i;
p2 = p1;
Page 11 of 11
}
RAM DIAGRAMS.
FREE
FREE
FREE
FREE
FREE
i RESERVED x01
RESERVED
p1 x02
RESERVED
p2 x03
I 15 x01
x01
p1 x02
x02
p2 x03
//Pointers variables
#include <iostream>
Page 12 of 12
using namespace std;
int main()
int i = 15;
int j = 30;
int *p1;
int *p2;
p1 = &i;
p2 = &j;
RAM DIAGRAMS.
FREE
FREE
FREE
FREE
FREE
RESERVED
RESERVED
Page 13 of 13
i RESERVED x01
RESERVED
j x02
p1 x03
p2 x04
15
i x01
30
j x02
x01
p1 x02 x03
p2 x04
Page 14 of 14
The name of the book used is “C++ Primer" by Stanley B. Lippman, Josée Lajoie, and
Barbara E. Moo pdf download”
Page 15 of 15