Thread: Does This Program Work For Anyone???

  1. #16
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    here's your code......

    dineout.hpp
    Code:
    #ifndef INCLUDED_DINEOUT_H
    #define INCLUDED_DINEOUT_H
    #endif
    
    class DineOut
    {
    public:
    	DineOut(int value);
    	~DineOut();
    	
    	int FiftyTimes();
    	int Twice();
    	int AddFive();
    	int HadBirth();
    	int NotHadBirth();
    
    
    private:
    	int x;
    };
    
    
    DineOut::DineOut(int value)
    {
    	x=value;
    }
    
    DineOut::~DineOut()
    {
    }
    
    int DineOut::FiftyTimes()
    {
     return x*=50;
    }
    
    int DineOut::Twice()
    {
     return x*=2;
    }
    
    int DineOut::AddFive()
    {
     return x+=5;
    }
    
    int DineOut::HadBirth()
    {
     return x+=1753;
    }
    
    int DineOut::NotHadBirth()
    {
     return x+=1752;
    }
    main.cpp

    Code:
    #include <iostream>
    using namespace std;
    #include "dineout.hpp"
    
    
    int main()
    {
      int i;
      cout << "Enter the number: " <<flush;
      cin >> i;
      DineOut myObject(i);
      cout << i << " after adding 5: " << myObject.AddFive() << endl;
      cout << i << " after adding 1753: " << myObject.HadBirth() << endl;
      return 0;
    }

  2. #17
    Registered User
    Join Date
    Sep 2002
    Posts
    49
    Code:
    #ifndef INCLUDED_DINEOUT_H
    #define INCLUDED_DINEOUT_H
    
    class DineOut
    {
     public:
     DineOut(); //void constructor
     ~DineOut(); //void destructor
     int FiftyTimes(int x);
     int Twice(int x);
     int AddFive(int x);
     int HadBirth(int x);
     int NotHadBirth(int x);
    
     private:
     int x;
    };
    
    DineOut::DineOut()
    {
    int x=1;
    }
    
    DineOut::~DineOut()
    {
    }
    
    
    int DineOut::FiftyTimes(int x)
    {
     return x*=50;
    }
    
    int DineOut::Twice(int x)
    {
     return x*=2;
    }
    
    int DineOut::AddFive(int x)
    {
     return x+=5;
    }
    
    int DineOut::HadBirth(int x)
    {
     return x+=1753;
    }
    
    int DineOut::NotHadBirth(int x)
    {
     return x+=1752;
    }
    
    #endif
    
    
    #include <iostream>
    #include <cstdlib>
    #include "DineOut.h"
    
    int main()
    {
     using namespace std;
     int EatOut;
     int YearBorn;
     int FinalNumber;
     int HaveYouHadBirth;
    
     cout<<"DINING OUT MATHEMATICS."<<endl<<endl;
     system("PAUSE");
     cout<<endl;
     cout<<"\t"<<"Here is some really neat math!"<<endl;
     cout<<"\a\v";
     cout<<"First, enter the number of times that "<<endl;
     cout<<"you would like to dine out a week."<<endl;
     cout<<"(This number must be >1 but <10.)"<<flush;
     cout<<endl<<endl<<"\t";
     cin>>EatOut;
     DineOut LetsEat(EatOut);
     cout<<endl<<endl;
     cout<<"Now, we will multiply this number by 2."<<endl;
     cout<<"(Just to be bold!)";
     cout<<endl<<endl<<"\t";
     cout<<EatOut<<" x 2 = "<<LetsEat.Twice()<<endl<<endl;
     system("PAUSE");
     cout<<endl<<endl;
     cout<<"Now, we will add 5 for Sunday.";
     cout<<endl<<endl<<"\t";
     cout<<EatOut<<" + 5 = "<<LetsEat.AddFive()<<endl<<endl;
     system("PAUSE");
     cout<<endl<<endl;
     cout<<"Now Multiply it by 50.";
     cout<<endl<<endl<<"\t";
     cout<<EatOut<<" x 50 = "<<LetsEat.FiftyTimes()<<endl<<endl;
     system("PAUSE");
     cout<<endl<<endl;
     cout<<"Now, if you've had your birthday, please press 1. ";
     cout<<endl<<"If you haven't, please press two.";
     cout<<endl<<"\t";
     cin>>HaveYouHadBirth;
     if (HaveYouHadBirth==1)
     {
     cout<<endl<<endl;
     cout<<"Since you've had your birthday, we'll add 1753.";
     cout<<endl<<endl<<"\t"<<EatOut<<" + 1753 = "<<LetsEat.HadBirth();
     cout<<endl<<endl;
     system("PAUSE");
     }
     else if (HaveYouHadBirth==2)
     {
     cout<<endl<<endl;
     cout<<"Since you haven't had your birthday, we'll add 1752.";
     cout<<endl<<endl<<"\t"<<EatOut<<" + 1752 = "<<LetsEat.NotHadBirth();
     cout<<endl<<endl;
     system("PAUSE");
     }
     else
     {
     cout<<"You have not entered a valid number.\a"<<endl<<"\a"<<endl;
     system("PAUSE");
     cout<<"This program will therefore not work correctly.";
     }
     cout<<endl<<endl;
     cout<<"Now, enter the year you were born.";
     cout<<endl<<endl<<"\t";
     cin>>YearBorn;
     cout<<endl<<endl;
     cout<<"Now, we will subtract the year you were born.";
     FinalNumber=EatOut - YearBorn;
     cout<<endl<<endl<<"\t"<<EatOut<<" - "<<YearBorn<<" = "<<FinalNumber;
     cout<<endl<<endl;
     system("PAUSE");
     cout<<endl<<endl;
     cout<<"Finally, you should be left with a three digit number.";
     cout<<endl<<endl<<"\t"<<FinalNumber;
     cout<<"The first digit is the number of times you would like to"<<endl;
     cout<<"dine out a week."<<endl;
     cout<<"The last two numbers are:"<<endl<<"duh duh duh duuuuuuuuuhhhhhhh!!!"<<endl;
     cout<<"YOUR AGE!!! HAHAHA!!!";
     system("PAUSE");
     return 0;
    
    
    }

    50 DineOut.h candidates are: int DineOut::NotHadBirth(int)

    23 diningoutmath.cpp no matching function for call to `DineOut:ineOut (int &)'

    20 DineOut.h candidates are: DineOut:ineOut()

    It repeats these comments for different lines throughout the program, why?
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  3. #18
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Your .CPP file is almost correct, but your class is still very incorrectly defined. None of those functions should take parameters except the constructor.

    Use CodingMaster's version of the class; it's much closer to what you need.

  4. #19
    ___
    Join Date
    Jun 2003
    Posts
    806
    Instead of putting cout on every output line and closing the statement can't he just do this


    Code:
    cout << "Blah Blah"
            << endl 
            << "See I didnt' end those statements so I dont need cout";

    Instead of....

    Code:
    cout << "Blah blah";
    cout << endl;
    cout << Man what unneeded work I'm doing ending each time.";
    Will that work in normal compilers? Its accepted in VC++ 6 but I don't know about the others..
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. threaded program doesn't work?
    By OcTO_VIII in forum Linux Programming
    Replies: 1
    Last Post: 12-11-2003, 12:37 PM
  3. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 11:05 AM
  4. Can't get program to work
    By theirishrover12 in forum C Programming
    Replies: 1
    Last Post: 06-08-2002, 11:10 AM
  5. how does this program work
    By ssjnamek in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2002, 01:48 PM