UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
Our Sponsors
Sponsor Advertisements help keep UGN Security Online.



Sponsor Advertisements help keep UGN Security Online.

Want to earn prizes for clicking online advertisements? Join Rewards1.com.
Latest Postings
Hello Everyone
by Cyrez
Today at 05:45 PM
Tracfone ESN Generator
by Zanvin Green
01/18/12 03:31 PM
Latest Reviews
Signup Today!
Welcome to the UGN Security forums! You are currently viewing our forums as a guest which gives you limited access to most of our discussions and access to other features.

By joining our free community you will have access to post topics, communicate privately with our users (PM), respond to polls, upload content, and access many other features. Registration is fast, simple, and absolutely free; so please join our community today!

If you have any problems with the registration process or your account login, please contact us.
Topic Options
Rate This Topic
#17450 - 09/18/04 04:31 AM hmm my output is all funky... c++ help
Rapture Offline
Member

Registered: 04/23/02
Posts: 212
Loc: Redwood
Just trying to store movie title, year, rating.

here's my code...

Code:
#include <iostream>
#include <cstdio>
using namespace std;

class Movie
{
    public:
    	Movie(char title, int year, int rating);	
	void print();
    
    private:
      char m_title;
    	int m_year;
    	int m_rating;
};

Movie::Movie(char title, int year, int rating)
{
    m_year = year;
    m_rating = rating;
    m_title = title;
}

void
Movie::print()
{
    cout << "Year: " << m_year << "," << m_title << ", rating = " << m_rating << endl;
}


int
main()
{
    Movie *data[100];	// array to hold the dynamically created Pair objects
    int num_movies = 0;	// the number of pair objects we have created
    char *title;
    int year, rating;		// hold values read from cin

    // as long as there is an integer to read, read it (as long as not EOF)
    while (cin >> title) 
    gets(title);
    {
	//read 2nd integer in pair (dangerous assumption, what if no more nums?)
        cin >> year; 
        
        //
        cin >> rating;

	// instantiate a new Pair object using the new operator
	data[num_movies] = new Movie(*title, year, rating);

	// we have read another pair of integers, update our counter
	num_movies++;  
    }

    // print out all the pairs pointed to by the data array
    for (int i = 0; i < num_movies; i++)
    {
    	cout << i << endl;
    	data[i]->print();
    }

}
after i compile and run i'm getting crazy output like this:

year: -3242342 , rating = -12342354

won't dispaly the title at all and give me crazy output like that. Any ideas on what I'm doing wrong here?

thanks

Top
Our Sponsors
Sponsor Our Sponsors

Sponsor Advertisements help keep UGN Security Online.



Sponsor Advertisements help keep UGN Security Online.
Top  
#17451 - 09/28/04 08:27 PM Re: hmm my output is all funky... c++ help
zenon Offline
Junior Member

Registered: 03/31/02
Posts: 93
Loc: Sweden
First of all, your class has a litle mistake.

the char title;
shoulde be char *title;
this because you know hold a single char.

So, I supose that this maybe fucks it.
Try it out, also do some controlls by adding some few lines like;

cout << title << endl;

just before reading data with

cin >> year;

try that.
_________________________
- "It's not my code that's useless
it's you loosers being unable to
apprecitate it because of your
lack of skills!"
/zenon - C++ master Apprentice

Top




Featured Member
Registered: 03/02/02
Posts: 133
Forum Stats
7175 Members
46 Forums
20072 Topics
55238 Posts

Max Online: 1567 @ 04/25/10 05:20 AM
Top Posters
UGN Security 13237
Gizmo 7188
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
buster9, Zanvin Green, mike g, btkilla41, vien muc
7174 Registered Users
Who's Online
1 registered (Cyrez), 358 Guests and 288 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!