Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// writing into a binary file #include <iostream> #include <fstream> #include <s

ID: 3651984 • 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[movie_lenght]; //name of movie
unsigned int numberCopies; //number of copies
char videoType[50]; //type of video
Video() // Constructor
{
char movieTitle[] = "NA";
numberCopies = -1;
char 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

when u r writing this vd[0].movieTitle = "Indiana"; that means movieTitle must have 8 characters as Indiana have 8 characters but ur movie length is 81 thats y u r getting the error so, instead of char movieTitle[movie_lenght]; write char *movieTitle;