CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Assignment (easy i guess) class,array

    Assignment HELP! (ALMOST DONE!) class, member function array..(with comment

    A corporation has six divisions, each responsible for sales to different geographic locations.
    Design a DivSales class that keeps sales data for a division, with the following
    members:
    • An array with four elements for holding four quarters of sales figures for the division
    • A private static variable for holding the total corporate sales for all divisions for the
    entire year.
    • A member function that takes four arguments, each assumed to be the sales for a quarter.
    The value of the arguments should be copied into the array that holds the sales data.
    The total of the four arguments should be added to the static variable that holds the total yearly corporate sales.

    •A function that takes an integer argument within the range of 0 to 3.

    The argument is to be used as a subscript into the division quarterly sales array.

    The function should return the value of the array element with that subscript.

    Write a program that creates an array of six DivSales objects. The program should ask the user to enter the sales for four quarters for each division.

    After the data is entered, the program should display a table showing the division sales for each quarter.

    The program should then display the total corporate sales for the year.

    Input Validation: Only accept positive values for quarterly sales figures.

    HTML Code:
    //PROGRAM COMPILES LIKE THIS. BUT DONT KNOW HOW TO DO THE ARRAY FOR QUARTERLY ON THE CLASS AND FEW OTHER THINGS
    
    #include <iomanip>
    #include <iostream>
    using namespace std;
    
    class DivSales      // Class name
    {
    
    private:            //Private function variables
    static float corpSales;       // it has to be static, but when i try it it gives me error
    float divSales;
    
    public:
    DivSales() {divSales = 0;}  //constructor initialization, not sure of this
    
                                // here it suppose to be an member function with array for the quarterly but i don't understand how to do it.
    
    void addDivSales (float s, float s2, float s3, float s4)          // Member function passing parameter
    { divSales += s; corpSales += divSales;}        // operations (not quite sure)
     float getDivisionSales () {return divSales;}   // returning values for displaying
      float getCorpSales () { return corpSales;}
    };
    
    float DivSales::corpSales=0;
    
    //main
    
    int main ()
    
    {
    
    
    
    DivSales divisions [6];     //class with object array
    
    int count;
    
    for (count = 0; count < 6; count ++)     //loop for prompting user for values
    {
    float sal = 0,sal_2 = 0,sal_3 = 0,sal_4 = 0;  // variable initialization
    
    cout << "Enter the 4 sales for each division ";     //prompting user
    
    cout << (count + 1) << " : ";       //displaying the loop divisions
    
    cin >> sal >> sal_2 >> sal_3 >> sal_4;
    divisions[count].addDivSales(sal,sal_2,sal_3,sal_4);      //) passing sal to member function addDivsales to do operation
    }
    
    cout << setprecision(2);
    cout << showpoint << fixed;
    cout << "\nHere are the division sales: \n";
    
    for (count = 0; count < 6; count++)      //loop for displaying the numbers the user input
    {
    cout << "Division " << (count + 1) << " $ ";
    cout << divisions[count].getDivisionSales() << endl;    // not quite sure, i follow instructions from my course.. 
                                                            // but it display what user put into each division, guess it adds s to divSales
    
    }
    
    cout << "Total corporate sales:\t$ ";             
    cout << divisions[0].getCorpSales() << endl;        // displaying the TOTAL CORPORATE SALES on the member function ( but I get wrong number )
    
    return 0;
    
    
    } 

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Assignment (easy i guess) class,array

    Quote Originally Posted by juliani2791 View Post
    Code:
    //PROGRAM COMPILES LIKE THIS. BUT DONT KNOW HOW TO DO THE ARRAY FOR QUARTERLY ON THE CLASS AND FEW OTHER THINGS
    ...
    class DivSales      // Class name
    {
    private:            //Private function variables
    static float corpSales;       // it has to be static, but when i try it it gives me error
    ...
    1. Your code is absolutely unreadable since you use HTML instead of the Code tags and avoid any proper indentations!
    2. It is not clear whether PROGRAM COMPILES LIKE THIS or it it gives me error
    Last edited by VictorN; October 9th, 2012 at 01:10 AM.
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Assignment (easy i guess) class,array

    [ Removed duplicate thread ]

    Please do not start multiple threads on the same subject.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured