Hi there! I'm trying to write a program to take a file with various information about a film, and read the text into an array on the main program. I'm having trouble figuring out how to actually read the text into the file. I'm trying the getline function without much success. The error that I'm getting in the getMovie function is that there's no instance of the function that matches the argument list. If you can figure out what I'm doing wrong, I'd appreciate it a bunch. Thanks!
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
usingnamespace std;
constint SIZE = 20;
struct dateType
{
int month;
int day;
int year;
};
struct movieType
{
string title;
string director;
int length;
dateType theaterReleaseDate;
dateType dvdReleaseDate;
double productionCost;
double firstYearRevenue;
};
int main()
{
movieType movieLibrary[SIZE];
ifstream myFile;
myFile.open("P2_myBooks.dat");
getMovie(movieLibrary, myFile);
//addMovie(movieLibrary);
//printMovie(movieLibrary);
//allPrintMovie(movieLibrary);
system("pause");
return 0;
}
void addMovie(movieType addMov[])
{
int i = 0;
cout << "What position in the array?: ";
cin >> i;
cout << "Enter the title: ";
cin >> addMov[i].title;
cout << "Director: ";
cin >> addMov[i].director;
cout << "Length: ";
cin >> addMov[i].length;
cout << "Theater Release Date Day (Day, Month, Year): ";
cin >> addMov[i].theaterReleaseDate.day >> addMov[i].theaterReleaseDate.month >> addMov[i].theaterReleaseDate.year;
cout << "DVD Release Date Day (Day, Month, Year): ";
cin >> addMov[i].dvdReleaseDate.day >> addMov[i].dvdReleaseDate.month >> addMov[i].dvdReleaseDate.year;
cout << "Production Cost: ";
cin >> addMov[i].productionCost;
cout << "First year Revenue: ";
cin >> addMov[i].firstYearRevenue;
return;
}
void printMovie(movieType prMov[])
{
string name;
cout << "Which movie in the array would you like to print? Enter the title: ";
cin >> name;
for (int i = 0; i <= SIZE-1; i++)
if (name == prMov[i].title)
{
cout << "Title: " << prMov[i].title;
cout << "Director: " << prMov[i].director;
cout << "Length: " << prMov[i].length;
cout << "Theater Release Date : " << prMov[i].theaterReleaseDate.day << prMov[i].theaterReleaseDate.month << prMov[i].theaterReleaseDate.year;
cout << "DVD Release Date Day : " << prMov[i].dvdReleaseDate.day << prMov[i].dvdReleaseDate.month << prMov[i].dvdReleaseDate.year;
cout << "Production Cost: " << prMov[i].productionCost;
cout << "First year Revenue: " << prMov[i].firstYearRevenue;
}
return;
}
void allPrintMovie(movieType allPrMov[])
{
int i = 0;
while (i < 100)
{
cout << "Title: " << allPrMov[i].title;
cout << "Director: " << allPrMov[i].director;
cout << "Length: " << allPrMov[i].length;
cout << "Theater Release Date : " << allPrMov[i].theaterReleaseDate.day << allPrMov[i].theaterReleaseDate.month << allPrMov[i].theaterReleaseDate.year;
cout << "DVD Release Date Day : " << allPrMov[i].dvdReleaseDate.day << allPrMov[i].dvdReleaseDate.month << allPrMov[i].dvdReleaseDate.year;
cout << "Production Cost: " << allPrMov[i].productionCost;
cout << "First year Revenue: " << allPrMov[i].firstYearRevenue;
cout << endl;
i++;
}
return;
}
void getMovie(movieType gtMov[], ifstream & myFile)
{
if (myFile.is_open);
{
for (int i = 0; i <= SIZE; i++)
{
myFile.getline(gtMov[i].title);
myFile.getline(gtMov[i].director);
myFile.getline(gtMov[i].length);
myFile.getline(gtMov[i].theaterReleaseDate.month, '/');
myFile.getline(gtMov[i].theaterReleaseDate.day, '/');
myFile.getline(gtMov[i].theaterReleaseDate.year);
myFile.getline(gtMov[i].dvdReleaseDate.month, '/');
myFile.getline(gtMov[i].dvdReleaseDate.day, '/');
myFile.getline(gtMov[i].dvdReleaseDate.year, '/');
myFile.getline(gtMov[i].productionCost);
myFile.getline(gtMov[i].firstYearRevenue);
}
}
return;
}
P2_myBooks.dat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
War of the Worlds
Byron Haskin
88
01/01/1953
01/01/2000
15000000.0
28000000.0
War of the Worlds
Stephen Spielberg
118
01/01/2005
01/01/2007
22000000.0
14000000.0
double someFunction( double, int ); // Prototype
int main()
{
double a = 3.5;
int b = 2;
double c;
c = someFunction( a, b );
}
double someFunction( double x, int y ) // Definition
{
return x * y;
}