I have a program for class where I have to read a file of with names and numbers into a class of objects and dynamically allocate it.
Header file
#include <string>
#include<cstring>
using namespace std;
class Movie
{
private:
string movies;
float rating;
double profit;
public:
Movie()
{
movies = "";
rating = 0.0;
profit = 0;
}
Movie(string, float, double);
void FindParticularRating(string, int);
float FindHighestRating();
void FindHightBoxOffice();
void PrintAll(int);
~Movie()
};
Functions
#include <iostream>
#include <string>
#include <cstring>
#include "Movie.h"
using namespace std;
Movie::Movie(string m,float r,double p)
{
movies = m;
rating = r;
profit = p;
}
void Movie::FindParticularRating(string name, int size)
{
if(name == movies)
cout << "The rating of that movie is " << rating << endl;
}
float Movie::FindHighestRating()
{
return rating;
}
Main.cpp
#include <iostream>
#include <string>
#include <fstream>
#include "Movie.h"
using namespace std;
int main()
{
Movie *Oscars;
ifstream in;
in.open("oscars.txt");
int size;
in >> size;
in.ignore();
Oscars = new Movie [size];
The first line of the file reads 5, which is the number of lines in the file. Each line has a title, and then 2 separate numbers.