We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,325 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with Object Class reading a file in.

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.

1
Contributor
0
Replies
1
View
Bennys
Newbie Poster
2 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0946 seconds using 2.68MB