Thread: I Need An immediately Help plz

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    3

    Unhappy I Need An immediately Help plz

    Hi

    I'am a new user here and I really need this to be done.

    I hope from the experts help me as soon as possible.

    This is the Code and you will see the requirements Below it.


    ----------------
    Display 10.1
    ----------------

    Code:
    #include <iostream> 
    using namespace std:
    
    struct CDAcount
    {
    	
    	double balance;
    	double interest_rate;		
    	int term;
    
    };
    
    	void get_data(CDAcount& the_acount);
    	
    	int main()
    	{
    		CDAcount acount;
    		get_data(acount);
    		
    		double rate_fraction, interest;
    		rate_fraction = acount.interest_rate / 100.0;
    		interest = acount.balance*rate_fraction*(acount.term/12.0);
    		acount.balance = acount.balance + interest;
    		
    		cout.set(ios::fixed);
    		cout.setf(ios::showpoint);
    		cout.precision(2);
    		
    		cout << "When your CD matures in "
    			 << acount.term << "monthes, \n"
    			 << "it will have a palance of $"
    			 << count.palance << endl;
    			 
    		return 0;
    	}
    	
    
    
    	void get_data(CDAcount& the_acount)
    	{
    		cout << "Enter acount balance: $";
    		cin >> the_acount.balance;
    		
    		cout << "Enter acount interest rate: ";
    		cin >> the_acount.interest_rate;
    		
    		cout << "Enter the number of months until maturity \n"
    			 << "(must be 12 or fewer monthes): ";
    		cin >> the_count.term;
    		
    	}



    Q: Redefine CDAcount from Display 10.1 so that it is a class rather than a structure. Use the same member variables as in Display 10.1 but make them private. Include member functions for each of the following: one to return the initials balance, one to return the balance at maturuity, one to return the interest rate, and one to return the term. Include a constructor that sets all of the member variables to any specified values, as well as a default constructor. Also, include an input member function with one formal parameter of type istream and an output member function with one formal parameter of type ostream. Embed your class definition in a test program.


    Thanks to every 1 for your efforts

    Your new Brother / SonY

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    I spot two typos. Check the spelling of your variables.

    Edit: Also, it should be
    Code:
    using namespace std;
    (semicolon, not colon)

    Edit: Correction, at least 3 misspelled variables (including struct members).
    Last edited by robatino; 10-05-2007 at 08:27 PM.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Yes, and the compiler should be telling you (the OP) where/what exactly those problems are so what's the deal?

    [edit]And read the posting guidelines... particularly items 2 and 3 below:
    Some issues of netiquette to particularly note are:
    1. Don't use all caps
    2. Use descriptive subject lines
    3. Do not put URGENT!, or NEED HELP NOW, etc. in your title; it will not make people look at it any faster. Doing this makes many old time helpers on this board not look at the post at all.
    [/edit]
    Last edited by hk_mp5kpdw; 10-05-2007 at 08:59 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    3
    thanks for your response and your advices

    but the question that I'm asking about is how to make the same program using Classes instead of structure.

    at least give me some pushes.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Structs and classes are essentially the same thing in C++. So the only change to make it use a class instead of struct would be:

    Code:
    class CDAcount
    {
    	public:
    	double balance;
    	double interest_rate;		
    	int term;
    
    };
    However, I assume you are supposed to move some functionality from main and elsewhere into this class by making them member functions.

    For example:
    Code:
    class CDAcount
    {
            public:
            void ReadData();
    	private:
    	double balance;
    	double interest_rate;		
    	int term;
    
    };
    
    void CDAcount::ReadData()
    {
        /* 
             read input from console and assign to member variables'
        */
    }
    [/code]
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Redefine CDAcount from Display 10.1 so that it is a class rather than a structure.
    In other words, I'm guessing that the code given was from "Display 10.1", and thus is valid C++; and that our new brother, SONY, just didn't copy it properly.

    Use the same member variables as in Display 10.1 but make them private.
    Easy enough.
    Code:
    class CDAcount
    {
    private:
    	double balance;
    	double interest_rate;		
    	int term;
    };
    Include member functions for each of the following: one to return the initials balance, one to return the balance at maturuity, one to return the interest rate, and one to return the term.
    Very simple as well, if you know how to write class member functions, since those function just return the values of variables. (They're sometimes called "get" functions.) If you don't know how, then check out this tutorial and this example:
    Code:
    class c {
    private:
        int var;
    public:
        int get_var();
    };
    
    int c::get_var() {
        return var;
    }
    Or, with simpler syntax that requests that get_var be made inline:
    Code:
    class c {
    private:
        int var;
    public:
        int get_var() { return var; }
    };
    I'd actually use the second method, since it's such a trivial function; but for most function you should use the first method.

    Include a constructor that sets all of the member variables to any specified values, as well as a default constructor.
    So you probably need a CDAccount() and CDAccount(double, double, int). The syntax for constructors is a little different than normal class member functions. Check out the tutorial I linked to earlier: http://www.cprogramming.com/tutorial/lesson12.html

    (I'm assuming that CDAcount is just CDAccount misspelled.)

    Also, include an input member function with one formal parameter of type istream and an output member function with one formal parameter of type ostream.
    You'll need something along the lines of
    Code:
    void c::read(istream &i);
    void c::write(ostream &o);
    Embed your class definition in a test program.
    Left as an exercise to the programmer . . .
    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.

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    9
    plase what the answer in this question

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    dwks has given everything you need to know without completely giving the answer. If you still can't get it, ask a question but don't ask for the answer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM