Someone please help me with this

This is a discussion on Someone please help me with this within the C++ Programming forums, part of the General Programming Boards category; /* I'm in computer programming 1b. so the libraries and styles maybe noobish, but i am having trouble with expanding ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    4

    Someone please help me with this

    /* I'm in computer programming 1b. so the libraries and styles maybe noobish, but i am having trouble with expanding the array to keep the inventory expanding...so it prints out all the albums when print is called and keeps them all in memory...i need to know placement of the arrays */


    Code:
    #include <iostream.h>
    #include <lvp\string.h>
    #include  <lvp\vector.h>
    
    
    
    struct rec{
    
    	long sku;
    	String artist;
    	String album;
    	long quantity;
    	double price;
    };//end struct
    
    struct inv{
    	inv();//constructer
    	vector<rec>album;
    };
    
    inv::inv()
    :album(0)
    
    {}
    
    /////////////////////////////////////////////////////////////////	
    void read(rec&rec);//reads in records at start
    void printer(rec&rec);//prints records
    void add(rec&rec);//adds records to inventory
    void del(rec&rec);//deleted records in inventory
    void sell(rec&rec);//sells available inventory
    
    int main(){
    	rec rec;
    	inv inv;
    	char answer;//answer for adding a new record at start
    	int menu_answer;//answer for menu
    	cout<<"\t\t\tThis Register Open"<<endl<<endl;
    	do{	
    		cout<<"Would you like to add a new record to inventory(y/n)? ";
    		cin>>answer;
    		if((answer=='y'||answer=='Y')){
    			read(rec);
    		}//end if
    		else{
    			break;
    		}//end else
    
    		
    		
    
    	}while((answer!='N')||(answer!='n'));
    	system("cls");
    
    	
    	do{
    	cout<<"Dj Mega Emporium"<<endl;
    	cout<<"\tMain Menu"<<endl<<endl;
    	cout<<"1)\tSell a record."<<endl;
    	cout<<"2)\tAdd a record."<<endl;
    	cout<<"3)\tDelete a record."<<endl;
    	cout<<"4)\tPrint record inventory report."<<endl;
    	cout<<"5)\tExit"<<endl<<endl;
    	cin>>menu_answer;
    	system("cls");
    	
    
    	if(menu_answer==4){
    		printer(rec);
    		cout<<endl;
    	}//end if
    
    	else if(menu_answer==2){
    		add(rec);
    		cout<<endl;
    	}//end else if
    
    	else if(menu_answer==3){
    		del(rec);
    		cout<<endl;
    	}//end else if
    	
    	else if(menu_answer==1){
    		sell(rec);
    		cout<<endl;
    	}//end else if
    	else if(menu_answer==5){
    		cout<<"k bye"<<endl;return 0;
    	}//end else if
    	else{
    		cout<<"Please choose a correct option"<<endl<<endl;
    	}//end else
    
    	}while(menu_answer!=5);//end do while
    	system("cls");
    	cout<<"k bye dont come back"<<endl;
    	return 0;
    	
    }//end main
    
    void read(rec&rec){//reads in record data
    	cout<<"Enter the Sku Number: ";
    	cin>>rec.sku;
    	cout<<"Enter the Artist: ";
    	cin>>rec.artist;
    	cin.ignore(100, '\n');
    	cout<<"Enter the Album: ";
    	getline(cin,rec.album);
    	cout<<"Enter the Quantity: ";
    	cin>>rec.quantity;
    	cout<<"Enter the price: ";
    	cin>>rec.price;
    	cout<<endl<<endl;
    	cout<<"Record Added to Inventory"<<endl<<endl;
    	
    
    	return;
    }//ends function
    
    void printer(rec&rec){
    
    
    	cout<<"Sku #: "<<rec.sku<<endl;
    	cout<<"Artist: "<<rec.artist<<endl;
    	cout<<"Album: "<<rec.album<<endl;
    	cout<<"Quantity: "<<rec.quantity<<endl;
    	cout<<"Price: "<<rec.price<<endl;
    	return;
    }//ends function
    
    void add(rec&rec){
    	int adding;
    	cout<<"Please enter the sku number of the record you are adding ";
    	cin>>rec.sku;
    	cout<<endl;
    	cout<<"We already have "<<rec.quantity<<" copies of "<<rec.artist<<"-"<<rec.album<<" in our inventory"<<endl;
    	cout<<"How many would you like to add? ";
    	cin>>adding;
    	rec.quantity=rec.quantity+adding;
    }//ends function
    
    void del(rec&rec){
    	cout<<"Enter the sku number of the record to delete :";
    	cin>>rec.sku;
    	cout<<rec.artist<<"-"<<rec.album<<" has been deleted";
    
    }	//ends function
    
    void sell (rec&rec){
    	int purchasing;
    	do{
    	cout<<"Please enter the sku number of the record you are buying: "<<endl;
    	cin>>rec.sku;
    	cout<<endl;
    	cout<<"Please enter how many books you wish to purchase: "<<endl;
    	cin>>purchasing;
    	if(purchasing>rec.quantity){
    		cout<<"Please choose a smaller amount"<<endl<<endl;
    	}//end if
    	}while(purchasing>rec.quantity);//end do while
    	rec.quantity=rec.quantity-purchasing;
    }//ends function
    Last edited by Salem; 04-25-2007 at 02:37 PM. Reason: Code tags around the code only - OK

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    }while((answer!='N')||(answer!='n'));
    That is always true. Most likely you meant &&. Better yet, you could use
    Code:
    #include <cctype>
    
    } while(std::tolower(answer) != 'n');
    Also, using iostream.h is a bad idea. Search the board to find out why. It's better to use the standard <iostream> and add
    Code:
    using namespace std;
    or std:: before every function call or a using directive for each identifier.

    Talk about long lines. Code tags don't wrap, so don't put extra long code in them. And you can put text outside code tags as well.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    4
    i would if i could, but i have to use the assignment rules, and school supplied libraries...so yea... all im asking for is an array

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    i would if i could, but i have to use the assignment rules, and school supplied libraries...so yea... all im asking for is an array
    <iostream> is likely supplied. By the way, what is your school?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    4
    Quote Originally Posted by laserlight View Post
    <iostream> is likely supplied. By the way, what is your school?
    wootton high school

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Since you have included <lvp/vector.h>, you are probably supposed to use it to store your data? What exactly is the problem?

    [rant]
    Why on earth do they force you to use some third-party libraries instead of standard stuff? The vector class I downloaded looks like this (unless this is some ancient version - the first one on their list - this is pretty bad):

    Code:
    template <class itemType>
    class vector
    {
      public:
    
      // constructors/destructor
    	 vector( );                        // default constructor (size==0)
    	 explicit vector( int size );      // initial size of vector is size
    	 vector( int size, const itemType & fillValue ); // all entries == fillValue
    	 vector( const vector & vec );   // copy constructor
    	 ~vector( );                       // destructor
    
      // assignment
        const vector & operator = ( const vector & vec );
    
      // accessors
        int  length( ) const;                   // capacity of vector
    
      // indexing
        itemType &       operator [ ] ( int index );       // indexing with range checking
        const itemType & operator [ ] ( int index ) const; // indexing with range checking
    
      // modifiers
        void resize( int newSize );             // change size dynamically;
                                                // can result in losing values
      private:
    
        int  mySize;                            // # elements in array
        itemType * myList;                      // array used for storage
    };
    So,
    1) no push_back member. To add an item you'll need to check length(), resize() as needed, and finally insert the element with operator[];
    2) no iterators;
    3) capacity == size ? If you don't know the size beforehand, adding new elements is either going to be extremely inefficient, or you'll need to implement the resizing strategy yourself. Also, if you want to reserve some more space just in case, you'll need to manage a variable showing how many valid elements you have yourself.
    etc, etc

    In short, this is (barely) good as a student implementation of a dynamic container, but it is no good for any practical purpose.
    Standard <vector> (among with all other standard stuff) should come with the compiler, so there's no cost. Are you really using this Lawrenceville stuff only because this is the only study material available and you have no idea how to do the exercises (if there are any) using standard libraries.
    [/rant]

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    4
    i need to know where to put the array code and exactly what to store

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21