// writing into a binary file #include <iostream> #include <fstream> #include <s
ID: 3652034 • Letter: #
Question
// writing into a binary file#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int movie_lenght=81;
struct Video
{
char *movieTitle; //name of movie
unsigned int numberCopies; //number of copies
char *videoType; //type of video
Video() // Constructor
{
movieTitle = "NA";
numberCopies = 0;
videoType = "NA";
}
};
void display(Video *v, int size)
{
/* Write code for this function which displays
content of given array of Videos*/
}
int main () {
Video vd[3];
vd[0].movieTitle = "Indiana";
vd[0].numberCopies =2;
vd[0].videoType = "Action";
vd[2].movieTitle = "Mission";
vd[2].numberCopies =4;
vd[2].videoType = "Action";
fstream file("example.bin", ios::out|ios::binary);
//writeFile(file,"example.bin", vd);
if (!file.fail())
{
cout<<"writing now!"<<endl;
file.write((char *)vd, sizeof(vd));
/* Instead of (char*) you can use reinterpret_cast < char*> ( expression )
cout<<"Done"<<endl;
}
else cout << "Unable to open file";
file.close();
/* Write your file reading Code HERE and Display results*/
return 0;
}
}
Explanation / Answer
// writing into a binary file #include #include #include using namespace std; struct Video { string MovieTitle; //name of movie unsigned int numberCopies; //number of copies string videoType; //type of video Video() // Constructor { MovieTitle = "NA"; numberCopies = 0; videoType = "NA"; } }; void display(Video *v, int size) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.