Open Help Request

Here is where you can ask your fellow blog visitors for help also. Since we have a lot of visitors you might be able to get at least a pointer on how to tackle a problem. Please post the problem in the comment section and how you attempted to solve it. 

11 comments:

  1. Solution to 11176:
    class Counter
    {
    private:
    int counter;
    int limit;
    static int nCounters;

    public:
    Counter (int y, int z)
    {
    counter = y;
    limit = z;
    nCounters ++;
    }
    void increment ()
    {
    if(counter < limit)
    counter ++;
    }
    void decrement ()
    {
    if(counter > 0)
    counter --;
    }
    int getValue()
    {
    return counter;
    }
    static int getNCounters ()
    {
    return nCounters;
    }
    };

    int Counter::nCounters = 0;

    ReplyDelete
  2. Solution to 11235:
    bool isMultipleOf(int x, int y)
    {
    return x%y == 0;
    }

    ReplyDelete
  3. Monkey Business
    A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 7 array , where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday". The program should first prompt the user to input the data for each monkey, starting with "Sunday" for monkey #1, then monkeys #2 and #3, followed by "Monday" for monkey #1, then monkeys #2 and #3 and so on, through "Saturday". The program then creates a report that includes the following information, each properly labeled (see below):

    Average amount of food eaten per day by the whole family of monkeys.
    The least amount of food eaten during the week by any one monkey.
    The greatest amount of food eaten during the week by any one monkey.

    Input Validation: Do not accept negative numbers for pounds of food eaten. When a negative value is entered, the program outputs "invalid (negative) food quantity -- re-enter" and attempts to reread the value .

    Prompts And Output Labels: Decimal values should be displayed using default precision, i.e. do not specify precision. Each item read should be prompted for by a string of the form "Enter the food eaten by monkey #N on DAY:" when N is 1 or 2 or 3 and DAY is "Sunday" or "Monday" or ... or "Saturday". The output should be of the form:
    Average food consumed daily: 6.23
    The least daily food consumed was by Monkey #0 on Friday
    The most daily food consumed was by Monkey #2 on Sunday
    where the specific amount of food or specific monkeys or specific days identified depend on the actual input.

    ReplyDelete
  4. Chapter 6 challenge 14 pg 370

    The Middletown Wholesale Copper Wire Company sells spools of copper wiring for
    $100 each. Write a program that displays the status of an order. The program should
    have a function that asks for the following data:
    • The number of spools ordered.
    • The number of spools in stock.
    • Whether there are special shipping and handling charges.
    (Shipping and handling is normally $10 per spool.) If there are special charges, the
    program should ask for the special charges per spool.

    The gathered data should be passed as arguments to another function that displays
    • The number of spools ready to ship from current stock.
    • The number of spools on backorder (if the number ordered is greater than what is
    in stock).
    • Subtotal of the portion ready to ship (the number of spools ready to ship times
    $100).
    • Total shipping and handling charges on the portion ready to ship.
    • Total of the order ready to ship.
    The shipping and handling parameter in the second function should have the default
    argument 10.00.
    Input Validation: Do not accept numbers less than 1 for spools ordered. Do not accept
    a number less than 0 for spools in stock or shipping and handling charges.

    ReplyDelete
  5. Solution for Exercise 11239:

    Assume that minutes is an int variable whose value is 0 or positive. Write an expression whose value is "undercooked" or "soft-boiled" or "medium-boiled" or "hard-boiled" or "overcooked" based on the value of minutes. In particular: if the value of minutes is less than 2 the expression 's value is "undercooked"; 2-4 would be a "soft-boiled", 5-7 would be "medium-boiled", 8-11 would be "hard-boiled" and 12 or more would be a "overcooked".

    Answer:
    minutes < 2 ? "undercooked" : minutes <= 4 ? "soft-boiled" : minutes <= 7 ? "medium-boiled" : minutes <= 11 ? "hard-boiled" : "overcooked"

    ReplyDelete
  6. I am extremely new to programming and I am struggling with the basics in my CS2 class. The instructor kind of breezes over the information and so I am having a difficult time learning how to build/implement and test classes to ensure they work properly. Here is the class that I created (sum), here is its implementation (sum.cpp). I need help designing a program to see if my class actually works as designed. CAN ANYONE HELP OUT?

    //FILE: sum.h
    #ifndef SUM_H
    class sum
    // this class maintains an ongoing floating point sum which can be initialized to
    // any value, increased and/or decreased.
    {
    public:
    sum(); // constructor initializes sumValue to zero
    sum(float initval); // constructor initializes sumValue to initval;
    void add_to(float increase); // adds increase to sumVal
    float dec(float decrease); // subtracts decrease from sumVal
    float ret_sum(); // returns sumVal
    float ret_avg(float num); // returns sumVal divided by num
    private:
    float sumVal; // holds the ongoing sum
    };
    #define SUM_H
    #endif

    //FILE: sum.cpp
    #include "sum.h"

    sum::sum() //default constructor
    {
    sumVal = 0.0;
    }
    sum::sum(float initval) //overload constructor
    {
    sumVal = initval;
    return;
    }
    void sum::add_to(float increase) //adds increase to sumVal
    {
    sumVal++;
    return;
    }
    float sum::dec(float decrease) //adds decrease to sumVal
    {

    return sumVal--;
    }
    float sum::ret_sum() // returns sumVal
    {
    return sumVal;
    }
    float sum::ret_avg(float num) //returns average
    {
    float average = sumVal + num / 2;
    return average;
    }
    //end of file

    ReplyDelete
  7. I need help with #15 on page 223 in C++ 8th edition....anybody's assistance will be appreciated, thanks!

    ReplyDelete
  8. Hello, I need help with Chapter 7, programming challenges #14 & #19

    ReplyDelete
  9. I need help completing this assignment for my C++ class:

    Project Description
    A small market maintains an inventory of exactly 20 items. You will read these items from a file. Each item named will have an associated cost and a character code to indicate whether or not it is taxable. You will place your online order. A file will contain your "printed" receipt with the total amount of your order.

    Project Specifications
    Input for this project has two sources. The inventory of exactly 20 items (with cost and tax code for each) is read from an input file. The user must enter: the names of the input and output files, and the items to purchase (by the number code associated with each item.)

    Output also has two sources. The command line shows the names of the inventory items, the echo of the chosen item with its price and "taxable" if appropriate. The amount of the tax and the total amount due will appear on the command line screen when the user is finished. The tax rate is 7% (use .07 in your code.) The "printed" receipt will be on the output file. All the non-taxable items should be listed first followed by the taxable items, then the total amount of the tax, and last the total amount due.

    ReplyDelete