• HEXUS
  • HEXUS.tv
  • channel
  • gaming
  • lifestyle
  • trust
  • community
  • ESReality
  • HEXUS.community discussion forumsVisit Corsair.com

    Welcome to the HEXUS.community discussion forums forums.

    You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

    Go Back   HEXUS.community discussion forums > Welcome to HEXUS!

    Welcome to HEXUS! Let us know you have arrived in here - please don't post any questions though - these should go in the appropriate forum.

    Reply
     
    LinkBack Thread Tools
    Old 19-12-2007, 08:53 PM   #1 (permalink)
    Registered User
     
    Join Date: Dec 2007
    Posts: 0
    Thanks: 0
    Thanked 0 Times in 0 Posts
    please urgent help needed with c++ program

    modularize program code by using functions. You will produce two solutions: a) using global access functions, and b) using classes and member functions.

    a) Using Access Functions

    Write five Invoice access functions: setInvoice(), computeAmount(), getAmount(), printData() and a global client function computeAmount().

    Function setInvoice() has five parameters of types Invoice, character array (for name and for phone), long (for account number), double (for gallons used). It sets the fields of its Invoice parameters using the values of its other parameters. Call this function in the first loop in main() after the test for array overflow.

    Function computeAmount() has two parameters of type Invoice and double (for gallons used). It sets the value of the Invoice field 'amount' by adding the flat fee ($12) and the price per gallon ($0.05) multiplied by the number of gallons used (use global const symbolic values). Call this function in the first loop in main() after the call to setInvoice().

    Function printData() has one parameter of type Invoice. It prints the fields 'name' in width 16 and 'phone' in width 14 (both are left-aligned), the field 'account' (in width 11, right-aligned), the field 'gallons' (in width 9, right-aligned), the field 'amount' (in width 8, right-aligned). Call this function from the second loop in main() instead of printing bill data explicitly.

    Function getAmount() has one parameter of type Invoice. It returns the value if the parameter's field 'amount'. It is called from the global client function computeAmount(). This function has two parameters, an Invoice array and the count of valid elements in the array. It returns a double value that the total of all amounts in the array. This function computeAmount() defines a double local variable 'amount', goes in a FOR loop through all valid elements of the parameter array, calls getAmount() for each valid component of the parameter array and adds the return value of getAmount() to 'amount'. At the end, computeAmount() returns the accumulated tally. Call this function from main() to initialize the value of local variable 'total' (after the printing loop).

    Pass structure variables by reference; pass built-in types by value; use the const modifier for structure and for array parameters that do not change as the result of the function execution. There is no need to use prototypes or multiple files: you will do that later. Instead, place the functions in the source code file between the structure definition and the start of main().

    Turn in the source code, the results of test runs and your explanations why you think that using access functions is better than making necessary computations in-line. Explain how the compiler distinguishes between two functions with the same name computeAmount().

    b) Using Classes and Member Functions

    Convert the Invoice access functions setInvoice(), computeAmount(), getAmount(), printData() into member functions of class Invoice. In the main() client code, send messages to Invoice objects instead of passing these Invoice objects to access functions as parameters.

    The simplest way to accomplish this task is to convert the access functions one by one. Use the keyword struct rather than class, leave data members public for a while, so that the program could be compiled and tested incrementally. There is no need to implement the functions outside the class specification. There is no need to use constructors and destructors: you will do that later.

    First, move the Invoice closing brace and the semicolon beyond the access function setInvoice() so that this function becomes an Invoice member function. Change the parameter list of setInvoice(); in main(), comment out the function call to setInvoice() and send a setInvoice() message to an Invoice target instead. Compile and run the program, make sure it runs correctly.

    Next, move the Invoice closing brace and the semicolon beyond the access function computeAmount(). Change the parameter list of computeAmount(); in main(), comment out the function call to computeAmount() and replace it with a computeAmount() message. Compile and run the program, make sure it runs correctly.

    Next, move the Invoice closing brace and the semicolon beyond the access function printData(). Change its parameter list; in main(), comment out the function call to printData() and replace it with a message. Compile and run the program, make sure it runs correctly.

    Next, move the Invoice closing brace and the semicolon beyond the access function getAmount(). Change its parameter list; in the global client function computeAmount(), comment out the function call to getAmount() and replace it with a message getAmount() sent to the element of the Invoice array. Compile and run the program, make sure it runs correctly.

    Finally, make Invoice data members private and its member functions public. Make sure that the program runs as before.

    Make sure that all the member functions that do not change the state of the target object are labeled with the const modifier. All structure and array parameters that do not change as the result of the call also should be labeled with the const modifier.

    Turn in the source code, the results of test runs and your explanations why you think that using classes, member functions and access specifiers is better than using global access functions. Also explain a) the meaning of each const modifier you use in the program and the advantages of using them, b) how the compiler distinguishes from two functions with the same name computeAmount() .


    // Modularze function code by using functins
    // Produce two solutions
    // Using global access functons
    // Using classes and member functions
    #include <string> // class Invoice uses c++ standard string class
    using std::string;

    // Invoice class definition
    class Invoice
    {
    public:
    Invoice(string,string); // constructor
    void setInvoice(string); function that sets invoice
    string getInvoice(); function that gets the invoice
    void setcomputAmount(); function that computes amount
    string getcomputeAmount();
    void setAmount(); function to set amount
    string getAmount(); function to get amount
    void setprintData(); function to print data
    string getprintData(); function that gets prnt data
    void setcomputeAmount();
    string getcomputeAmount();

    private:
    string computAmount; // amount for invoice
    string getAmount;
    string printData; //print data for invoice
    string setInvoice;
    string computeAmount;



    } ; // end class Invoice


    I need help to complete this program and also the interface.thanks.
    haelly is offline   Reply With Quote
    Old 19-12-2007, 09:00 PM   #2 (permalink)
    Senior Member
     
    manwithnoname's Avatar
     
    Join Date: Dec 2005
    Posts: 838
    Thanks: 14
    Thanked 18 Times in 17 Posts
    Re: please urgent help needed with c++ program

    What do you need help with? If it all of it why not just quit the course assuming it is some homework?
    manwithnoname is offline   Reply With Quote
    Old 19-12-2007, 10:02 PM   #3 (permalink)
    Vampire
     
    Join Date: Jul 2003
    Location: London
    Posts: 1,675
    Thanks: 2
    Thanked 10 Times in 10 Posts
    Re: please urgent help needed with c++ program

    0th post asking for complete homework assignment ?

    All Hail the AACS : 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
    Sinizter is offline   Reply With Quote
    Reply

    Breadcrumb
    Go Back   HEXUS.community discussion forums > Welcome to HEXUS!


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Trackbacks are On
    Pingbacks are On
    Refbacks are On
    Forum Jump

    Similar Threads
    Thread Thread Starter Forum Replies Last Post
    Automatic update of program starts with launch of program desiboy9 Welcome to HEXUS! 0 18-06-2007 10:24 AM
    Urgent help needed daveham General discussion 7 21-12-2005 11:34 PM
    Urgent help needed XA04 Help - technical & advisory 5 15-12-2005 10:50 PM
    Urgent Help Needed Guys Howard HEXUS.hardware 20 29-02-2004 07:57 PM
    URGENT help needed Howard General discussion 5 18-08-2003 08:50 PM



    All times are GMT. The time now is 06:33 PM.

    Any representations/statements made on the HEXUS.community discussion forums are the representations/statements of the author i.e. the person/organisation making them. If any such representations/statements are disputed they are a matter between the parties concerned. HEXUS Limited accepts no responsibility for any misrepresentations, inaccurate or false statements made by any person/organisation other than HEXUS Limited employees.
    Powered by vBulletin® Version 3.7.4
    Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
    Content Relevant URLs by vBSEO 3.2.0
    © Copyright 2008 HEXUS® Limited. All rights reserved. Unauthorised reproduction strictly prohibited.