Questions
Learning Objectives After the successful completion of this learning unit, you will be able to: Implement...

Learning Objectives

After the successful completion of this learning unit, you will be able to:

  • Implement syntactically correct C++ arrays.
  • Solve a variety of standard problems using arrays.

Array Practice

I recommend that before you begin the assignment you write as many of these small ungraded programming challenges as you can. You should at least write 2 or 3 of them. They are a good way to gradually build up your confidence and skills. Of course, you'll have to write a program to test each function as well. Note that none of these functions should include any input or output!

  • Write a function named noNegatives(). It should accept an array of integers and a size argument. It should return true if none of the values are negative. If any of the values are negative it should return false

            bool noNegatives(const int array[], int size);
    
  • Write a function named absoluteValues(). It should accept an array of integers and a size argument. It should replace any negative values with the corresponding positive value.

            void absoluteValues(int array[], int size);
    
  • Write a function named eCount. It should accept an array of chars and a size argument. It should return the number of times that the character 'e' shows up in the array.

            int eCount(const char array[], int size);
    
  • Write a function named charCount. It should be similar to eCount, but instead of counting 'e's it should accept a third argument, a target char. The function should return the number of times the target char shows up in the array.

            int charCount(const char array[], int size, char targetChar);
    
  • Write a method named isSorted. It should accept an array of integers and a size argument. It should return true if the values are sorted in ascending order. False if they are not.

            bool isSorted(const int array[], int size);
    
  • Write a method named equalNeighbors. It should accept an array of chars and a size argument. It should return true if there are two adjacent elements in the array with equal values. If there are not, it should return false.

            bool equalNeighbors(const char array[], int size);
    

This is not a homework assignment, so feel free to post your code to one of these (not more than one) to the forum at any time.

For Credit

Assignment 4.1 [45 points]

Write a program that reads five (or more) cards from the user, then analyzes the cards and prints out the category of hand that they represent.

Poker hands are categorized according to the following labels: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card.

To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from 2 to 9. When your program runs it should start by collecting five integer values from the user and placing the integers into an array that has 5 elements. It might look like this:

Enter five numeric cards, no face cards. Use 2 - 9.
Card 1: 8 
Card 2: 7
Card 3: 8
Card 4: 2
Card 5: 3

(This is a pair, since there are two eights)

No input validation is required for this assignment. You can assume that the user will always enter valid data (numbers between 2 and 9).

Since we are ignoring card suits there won't be any flushes. Your program should be able to recognize the following hand categories, listed from least valuable to most valuable:

Hand Type Description Example
High Card There are no matching cards, and the hand is not a straight 2, 5, 3, 8, 7
Pair Two of the cards are identical 2, 5, 3, 5, 7
Two Pair Two different pairs 2, 5, 3, 5, 3
Three of a kind Three matching cards 5, 5, 3, 5, 7
Straight 5 consecutive cards 3, 5, 6, 4, 7
Full House A pair and three of a kind 5, 7, 5, 7, 7
Four of a kind Four matching cards 2, 5, 5, 5, 5

(A note on straights: a hand is a straight regardless of the order. So the values 3, 4, 5, 6, 7 represent a straight, but so do the values 7, 4, 5, 6, 3).

Your program should read in five values and then print out the appropriate hand type. If a hand matches more than one description, the program should print out the most valuable hand type.

Here are three sample runs of the program:

Enter five numeric cards, no face cards. Use 2 - 9.
Card 1: 8 
Card 2: 7
Card 3: 8
Card 4: 2
Card 5: 7
Two Pair!
Enter five numeric cards, no face cards. Use 2 - 9.
Card 1: 8 
Card 2: 7
Card 3: 4
Card 4: 6
Card 5: 5
Straight!
Enter five numeric cards, no face cards. Use 2 - 9.
Card 1: 9 
Card 2: 2
Card 3: 3
Card 4: 4
Card 5: 5
High Card!

Additional Requirements

1) You must write a function for each hand type. Each function must accept a const int array that contains five integers, each representing one of the 5 cards in the hand, and must return "true" if the hand contains the cards indicated by the name of the function, "false" if it does not. The functions should have the following signatures.

bool  containsPair(const int hand[])
bool  containsTwoPair(const int hand[])
bool  containsThreeOfaKind(const int hand[])
bool  containsStraight(const int hand[])
bool  containsFullHouse(const int hand[])
bool  containsFourOfaKind(const int hand[])

Note that there are some interesting questions regarding what some of these should return if the hand contains the target hand-type and also contains a higher hand-type. For example, should containsPair() return true for the hand [2, 2, 2, 3, 4]? Should it return true for [2, 2, 3, 3, 4]? [2, 2, 3, 3, 3]? I will leave these decisions up to you.

2) Of course, as a matter of good practice, you should use a constant to represent the number of cards in the hand, and everything in your code should still work if the number of cards in the hand is changed to 4 or 6 or 11 (for example).  Writing your code so that it does not easily generalize to more than 5 cards allows you to avoid the objectives of this assignment (such as traversing an array using a loop). If you do this, you will receive a 0 on the assignment.

3) You do not need to write a containsHighCard function. All hands contain a highest card. If you determine that a particular hand is not one of the better hand types, then you know that it is a High Card hand.

4) Do not sort the cards in the hand. Also, do not make a copy of the hand and then sort that.

5) An important objective of this assignment is to have you practice creating excellent decomposition.  Don't worry about efficiency on this assignment. Focus on excellent decomposition, which results in readable code. This is one of those programs where you can rush and get it done but end up with code that is really difficult to read, debug, modify, and re-use. If you think about it hard, you can think of really helpful ways in which to combine the tasks that the various functions are performing.  5 extra credit points on this assignment will be awarded based on the following criteria: no function may have nested loops in it. If you need nested loops, the inner loop must be turned into a separate function, hopefully in a way that makes sense and so that the separate function is general enough to be re-used by the other functions. Also, no function other than main() may have more than 5 lines of code. (This is counting declarations, but not counting the function header, blank lines, or lines that have only a curly brace on them.) In my solution I was able to create just 3 helper functions, 2 of which are used repeatedly by the various functions.

These additional criteria are intended as an extra challenge and may be difficult for many of you. If you can't figure it out, give it your best shot, but don't be too discouraged. It's just 5 points. And be sure to study the posted solution carefully.

Suggestions

Test these functions independently. Once you are sure that they all work, the program logic for the complete program will be fairly straightforward.

Here is code that tests a containsPair function:

int main() {
        int hand[] = {2, 5, 3, 2, 9};

        if (containsPair(hand)) {
                cout << "contains a pair" << endl;
        }
}

Submit Your Work

Name your source code file according to the assignment number (a1_1.cpp, a4_2.cpp, etc.). Execute the program and copy/paste the output that is produced by your program into the bottom of the source code file, making it into a comment. Use the Assignment Submission link to submit the source file. When you submit your assignment there will be a text field in which you can add a note to me (called a "comment", but don't confuse it with a C++ comment). In this "comments" section of the submission page let me know whether the program works as required.

Keep in mind that if your code does not compile you will receive a 0.

In: Computer Science

t CASE 2: AMAZON LTD Multibus Ltd manufactures four products namely; A, B, C and D...

t

CASE 2: AMAZON LTD

Multibus Ltd manufactures four products namely; A, B, C and D using the same plant and processes. The following data relate to the production activities of the company for the period ended 30th November 2008:

Product

Number of units

Material cost per unit (Sh)

Labour cost per unit (Sh)

Machine time per unit (hours)

A

500,000

5

0.5

0.25

B

5,000,000

5

0.5

0.25

C

600,000

16

2.0

1.00

D

7,000,000

17

1.5

1.50

            Additional information:

The production overhead costs incurred by the company over the period under consideration were analyzed as follows:

Sh.

                          Machine set up costs              4,355,000

                        Ordering costs                          1,920,000

                        Machining costs                       37,424,000

                        Quality control costs                7,580,000

                        Maintenance costs                   8,600,000

The production overheads were absorbed by the products based on machine hourly rate

An investigation into the production overhead activities for the period reveal the following:

Product

Number of machine set-ups

Number of material orders

Number of maintenance runs

Number of production runs

A

1

1

2

2

B

6

4

5

10

C

2

1

1

3

D

8

4

4

12

Required:

The production cost per unit using the machine hourly rate method      

The production cost per unit using the activity based costing method, tracing the overheads to production units by means of appropriate cost drivers     

Briefly comment on the differences in costs attributed to products A, B, C and D in b(i) and (ii) above                                                                                 

        

In: Accounting

For this written assignment, select one recent (within the last two years) evidence-based article from a...

For this written assignment, select one recent (within the last two years) evidence-based article from a peer reviewed nursing journal that describes a "best practice" in an area of nursing you are interested in. For example, if you would like to be a pediatric nurse, select an article that discusses a best practice in pediatric care.

Cite the article and provide a brief overview of how the results or findings were obtained. Then describe the "best practice." Conclude your discussion by explaining whether you thought the research findings supported the conclusions and the best practice.

This assignment must be no more than 3 pages long. It should include all of the required elements. Use APA Editorial format and attach a copy of the article.

In: Nursing

For this written assignment, select one recent (within the last two years) evidence-based article from a...

For this written assignment, select one recent (within the last two years) evidence-based article from a peer-reviewed nursing journal that describes a "best practice" in an area of nursing you are interested in. For example, if you would like to be a pediatric nurse, select an article that discusses a best practice in pediatric care.

Cite the article and provide a brief overview of how the results or findings were obtained. Then describe the "best practice." Conclude your discussion by explaining whether you thought the research findings supported the conclusions and the best practice.

This assignment must be no more than 3 pages long. It should include all of the required elements. Use APA Editorial format and attach a copy of the article.

Also, include reference or references.

In: Nursing

For this written assignment, select one recent (within the last two years) evidence-based article from a...

For this written assignment, select one recent (within the last two years) evidence-based article from a peer reviewed nursing journal that describes a "best practice" in an area of nursing you are interested in. For example, if you would like to be a pediatric nurse, select an article that discusses a best practice in pediatric care. Cite the article and provide a brief overview of how the results or findings were obtained. Then describe the "best practice." Conclude your discussion by explaining whether you thought the research findings supported the conclusions and the best practice. This assignment must be no more than 3 pages long. It should include all of the required elements. Use APA Editorial format and attach a copy of the article.

In: Nursing

Last Spring Sprint and T-Mobile announced to merge into one $146 billion company. The two companies...

  1. Last Spring Sprint and T-Mobile announced to merge into one $146 billion company. The two companies argued that the merger will lower costs, “create competition and lower prices across wireless, video, and broadband” as well as other 5G technologies.
  1. List all, and describe two of, the steps you will take to examine whether or not such a merger should be allowed to go ahead.
  2. How would an economist justify (defend) government involvement in the economy?
  3. Give two broad economic reasons to justify immigration into the USA, or why the US government should to fight Ebola in West Africa or international terrorism in far-away places. [To say Americans are kind people alone is not the answer!]

In: Economics

You are considering buying one of two machines. Machine A costs $5,000, should last 10 years,...

You are considering buying one of two machines. Machine A costs $5,000, should last 10 years, and will generate cash flows of $900/year. Machine B costs $8,000, should last only 6 years, and will generate cash flows of $1,900/year. The Discount Rate is 8%.

  1. What is the NPV and EAC of each project? Based on your analysis, which machine should you buy?
  2. Suppose instead that the cash flows occur at mid-year. (Assume the initial payment still occurs at the end of year 0).
    1. Compute the NPV and the EAC of each project.  
    2. Does your EACs increase or decrease? Does this make sense?
    3. Does your answer to Part A change?

In: Accounting

Management Accounting Question 1 - Identify two products you purchased in the last year—one for under...

Management Accounting

Question 1 - Identify two products you purchased in the last year—one for under $5 and one for over $100—and indicate whether you think they were accounted for using job order costing or process costing and why.

In: Accounting

Suppose the world price for a good is lower than the domestic price without trade. Explain...

Suppose the world price for a good is lower than the domestic price without trade. Explain the two sources of deadweight loss arising from a tariff.

IMPORTANT: I know that the two sources of deadweight loss arising from tariffs are inefficent production and lost transactions. However, I don't know why that is. Could you please explain to me why inefficent production and lost transactions are the two sources of deadweight loss arising from tariffs when the world price for a good is lower than the domestic price without trade? Thank you

In: Economics

A population of splendid fungus beetles lives in my backyard. A gene determines how many spots...

A population of splendid fungus beetles lives in my backyard. A gene determines how many spots they have on their hindwings. Those with the dominate phenotype (BB and Bb) have 3 large spots, and those with the recessive phenotype (bb) have 7 small spots. The population isn't very big - only 50 beetles. I counted them and notice that 18 have three large spots and 32 have seven small spots. If there is no natural selection, mutation or gene flow from another population (and mating is random), how much could the allele frequencies change in one generation just by chance?

In: Biology