Visual C++ 2010 Help - Simple Program

This is a discussion on Visual C++ 2010 Help - Simple Program within the C++ Programming forums, part of the General Programming Boards category; I just purchased Ivor Horton's "Beginning Visual C++ 2010" e-book and was attempting one of the practice problems (of which ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Visual C++ 2010 Help - Simple Program

    I just purchased Ivor Horton's "Beginning Visual C++ 2010" e-book and was attempting one of the practice problems (of which I do not have the solution) and was wondering if anyone be willing to help me write this (so called) simple C++ program in Visual Studio 2010? If possible, I would want comments beside each important section so that I may better understand the process of how the program works.

    Here is the program requirements...


    Practice Exercise #1
    Program Input

    The input to the program will be the product id number (a 5-digit identification number), the manufacturer's id number (a 4-digit identification number), the wholesale price of the
    product, the mark-up percentage for the product, the description of the product, and the quantity of product in stock.

    The following is an example of this input:

    Product ID #: 10001
    Manufacturer's ID #: 5020
    Wholesale Price: 15.00
    Mark-Up %: .20
    Product Description: 3.5" Floppy Disks
    Quantity In Stock: 140

    Output
    Prepare a listing of the inventory for the store with appropriate column headings. This listing should include the following:

    a. the product id number; integer
    b. the product description; character
    c. the manufacturer's id number; integer
    d. the wholesale price of the product; double
    e. the mark-up percentage for the product; double
    f. the quantity of product in inventory. integer

    The retail price for the product (the wholesale price increased by the mark-up percentage) should be printed as a separate item from the above listing.

    Processing
    1. The class variables, which represent a single product sold by the store, should include the following data members:

    (6 private members)
    a. the product id number integer
    b. the description of the product character array
    c. the manufacturer's id number integer
    d. the wholesale price of the product double
    e. the mark-up percentage for the product double
    f. the quantity of product in inventory integer

    2. The class should have the following member functions:

    (10 public members)
    a. Two constructors. The first is the default, which sets all of the members of the class to zero. The second constructor should enable the user to specify all of the initial attributes of the members of the class.
    b. Separate functions which return the values of the members of the class.
    c. A function that displays the values of the members of the class to the monitor (as described in the "output" section).
    d. A function that returns the class object's retail price (the wholesale price increased by the mark-up percentage).

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    We'd be willing to help, but you will get a lot more help if you make an attempt to get started.
    Don't worry, it doesn't need to be perfect, right or even working. Just a little something that shows you've gotten started.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Header File thus far...

    My Header File so far...

    How does it look??

    Code:
    //Specification File (Inventory.h)
    
    #ifndef INVENTORY_H
    #define INVENTORY_H
    
    
    #include <iostream>
    #include <iomanip>
    
    
    using namespace std;
    
    
    class Inventory
    {
    public:
        //Constructors
    
    
        Inventory ( );  //default constructor
        Inventory ( int, char[], int, double, double, int );
    
    
        //Return the value of the private members
    
    
        int GetProductId ( ) const;
        char* GetProductDescription ( ) const;
        int GetManufactId ( ) const;
        double GetWholesalePrice ( ) const;
        double GetMarkUp ( ) const;
        int GetQuantity ( ) const;
    
    
        //Display the Information Concerning Inventory
        void Display ( ) const;
    
    
    private:
        int ProductId;
        char ProductDescription;
        int ManufactId;
        double WholesalePrice;
        double Markup;
        int Quantity;
    };

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    What does the char* mean? (pointer?) I am kind of following along in the book, but it doesn't explain it very well. Curious why the product description would need to be a pointer...

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    Ok, I have got the program running. Now I just need to work on the output and a couple of formulas.

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    While you are working through your e-book, you may find some value in also perusing our C++ Made Easy Tutorials to clarify some of your questions you have with the book.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    thanks, i will check it out

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Some glaring problems...
    char is a character, not a string. Use std::string.
    char* is dangerous use a pointers for strings. Once again, use std::string.
    Also take heart the following lesson: SourceForge.net: Do not remove parameter names - cpwiki
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ and Visual Studio 2010
    By 03jh01 in forum C++ Programming
    Replies: 5
    Last Post: 10-03-2010, 04:03 AM
  2. Replies: 2
    Last Post: 08-28-2010, 12:58 AM
  3. C in Visual Studio 2010, simple code fails
    By Jaymond Flurrie in forum C Programming
    Replies: 13
    Last Post: 07-01-2010, 07:27 AM
  4. Windows 7 RC, Visual Studio 2010 Beta, Office 2010 beta, anyone in?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-20-2009, 01:57 PM

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