Granolaisgood's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
9 (0.02 per day)
Joined:
30-September 12
Profile Views:
92
Last Active:
User is offline Oct 07 2012 01:21 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Granolaisgood has not set their status

Posts I've Made

  1. In Topic: Compiler saying cout is undeclared despite having #include <iostre

    Posted 7 Oct 2012

    View PostKYA, on 07 October 2012 - 12:03 PM, said:

    Show us the entire file. Also your catch should have brackets.

    Even if you have the iostream header, you need to include the namespace as well or cout by itself or fully qualify it in your code.


    here it is
    /*
    Muhammad Zubair
    Assignment 2
    CSCI 235 Section 001
    */
    
    #ifndef _CS235_ABLIST_H_
    #define _CS235_ABLIST_H_
    
    
    #define LIST_MAX 10
    
    #include "ABCList.hpp"
    #include<iostream>
    using namespace std;
    template <class T>
    class ABList : public ABCList<T> {
    private:
    	T    a [LIST_MAX];
    	int  size;
    
    public:
    	     ABList ();
    
    	virtual bool isEmpty ();
    	virtual int  getLength ();
    	virtual void insert (int pos, T item);
    	virtual T    remove (int pos);
    	virtual T    retrieve (int pos);
    };
    
    
    template <class T>
    ABList<T>::ABList () {
    	size = 0;
    }
    
    template <class T>
    bool ABList<T>::isEmpty () {
    	if (size == 0)
    		return true;
    	return false;
    }
    
    template <class T>
    int  ABList<T>::getLength ()
    {
    	return size;
    }
    
    template <class T>
    void ABList<T>::insert (int pos, T item)
    {
    	try
    	{
    		if(pos < 1)
    			throw 2;
    		else
    		{
    		for(int i= size; i> i-1; i--)
    		{
    			item [i] = item [i-1];
    			item [pos-1] = item; 
    			++size;
    		}
    		}
    	}
    		catch(int x)
    			{cout << "Error Number" << x;}
    	
    }
    
    template <class T>
    T ABList<T>::remove (int pos)
    {
    	try
    	{
    		if(pos < 1)
    			throw 3;
    		else
    		{
    			T temp =  a[pos -1];
    		
    			for(int i = pos-1; i < size; i++)
    			{
    				a[i] = a [i+1];
    				--size;
    			}
    			return temp;
    		}
    	}
    	catch(int x)
    		{cout << "ERROR: " << x;}
    }
    
    template <class T>
    T ABList<T>:: retrieve (int pos)
    {
    	if(pos >= 1)
    		return a[pos - 1];
    	else
    		return NULL;
    }
    
    
    #endif
    
    


    View PostKYA, on 07 October 2012 - 12:03 PM, said:

    Show us the entire file. Also your catch should have brackets.

    Even if you have the iostream header, you need to include the namespace as well or cout by itself or fully qualify it in your code.


    Nevermind i got it.
  2. In Topic: getline() function is not storing user response.

    Posted 30 Sep 2012

    View Post#define, on 30 September 2012 - 02:47 PM, said:

    You probably need cin.ignore() before the getline() function. If put before cout can help tell if ignore is needed.

    cin.ignore();
    
    cout << "Name of Movie: "; 
    getline(cin,name); //User enters the name of the movie.
    
    // This function sets the movie's name 
    // into the class. 
    // (movieName) <-- name of variable that it is stored into
    m1.setMovieName(name);
    
    m1.movieNameShow();
    
    

    That worked. Wow, it was something so simple! Thank you!
  3. In Topic: getline() function is not storing user response.

    Posted 30 Sep 2012

    View PostSkydiver, on 30 September 2012 - 02:32 PM, said:

    Can you show us a screenshot of what you are seeing? By all indications your code should be working.

    Here it is
  4. In Topic: getline() function is not storing user response.

    Posted 30 Sep 2012

    View PostGranolaisgood, on 30 September 2012 - 02:00 PM, said:

    View Postjimblumberg, on 30 September 2012 - 01:55 PM, said:

    No I said name, this is the variable you are getting from the user before you insert it into the class.
    getline(cin,name); //User enters the name of the movie.
    cout << name << endl;
    


    This is to insure that the getline() is functioning properly. The other way would be to test your stream and insure it is not in an error state.


    Jim


    Yes name is a string too. And i just tried cout << name and that worked fine. Do you think it is the cin.ignore()? However without it it skips the getline() function.

    But why isn't it saving in the class?
  5. In Topic: getline() function is not storing user response.

    Posted 30 Sep 2012

    View Postjimblumberg, on 30 September 2012 - 01:55 PM, said:

    No I said name, this is the variable you are getting from the user before you insert it into the class.
    getline(cin,name); //User enters the name of the movie.
    cout << name << endl;
    


    This is to insure that the getline() is functioning properly. The other way would be to test your stream and insure it is not in an error state.


    Jim


    Yes name is a string too. And i just tried cout << name and that worked fine. Do you think it is the cin.ignore()? However without it it skips the getline() function.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Granolaisgood hasn't added any friends yet.

Comments

Granolaisgood has no profile comments yet. Why not say hello?