Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a two-part assignment which includes Pointer Tasks, and The League with DMA. 1. Pointer Tasks This part of the assignment will give you

This is a two-part assignment which includes Pointer Tasks, and The League with DMA.

1. Pointer Tasks

This part of the assignment will give you a chance to perform some simple tasks with pointers. The instructions below are a sequence of tasks that are only loosely related to each other. Start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one. For each step, include a comment in your program indicating which step you are completing in the following statement(s). The easiest way to do this is copy and paste the below into your main function first, and then fill in your statements.

// 1. Create two integer variables named x and y // 2. Create an int pointer named p1 // 3. Store the address of x in p1 // 4. Use p1 to set the value of x to 99 // 5. Using cout and x, display the value of x // 6. Using cout and the pointer p1, display the value of x // 7. Store the address of y into p1 // 8. Use p1 to set the value of y to -300 // 9. Create two new variables: an int named temp, and an int pointer named p2 // 10. Use temp, p1, and p2 to swap the values in x and y (this will take a few statements) // 11. Write a function with the following signature: void noNegatives(int *x). The function should accept the address of an int variable. If the value of this integer is negative then it should set it to zero // 12. Call the function twice: once with the address of x as the argument, and once with the address of y // 13. Use p2 to display the values in x and y (this will require both assignment statements and cout statements) // 14. Create an int array with two elements. The array should be named a // 15. Use p2 to initialize the first element of a with the value of x // 16. Use p2 to initialize the second element of a with the value of y // 17. Using cout, display the address of the first element in a // 18. Using cout, display the address of the second element in a // 19. Use p1, p2, and temp to swap the values in the two elements of array a. (first point p1 at a[0], then point p2 at a[1]. After this the swapping steps should look very similar to step 10.) // 20. Display the values of the two elements. (The first element should be 99, the second 0). // 21. Write a function named swap that accepts two integer pointers as arguments, and then swaps the two integers that the pointers point to. This function must be pass by pointer, i.e. int *, not pass by reference, i.e. int &. // 22. Call your swap function with the addresses of x and y, then print their values. (x should be 99, y should be 0). // 23. Call your swap function with the address of the two elements in array a, then print their values. (a[0] should be 0, a[1] should be 99)

2. The League with DMA

Rewrite your League program from Assignment 5 so that it uses Dynamic Memory Allocation (DMA) to create the team names and scores arrays.

This is a good test of the modularity of your program. You will only need to make slight modifications to your main() function if you wrote your original program using functions similar to the following:

void initializeData(string names[], int wins[], int size) void sort(string names[], int wins[], int size) void display(string names[], int wins[], int size)

Your modified league program should start out by asking the user how many teams will be entered. It should then dynamically allocate two appropriate arrays, and proceed just like the original League assignment, calling the above three functions. When your program is done using the arrays, don't forget to use delete [] to return their memory to the system.

Note: you must use dynamic memory allocation for your arrays, i.e. the new and delete [] operators, to receive credit.

The output from your program should look approximately like this (user input in orange bold):

How many teams will you enter?: 4 Enter team #1: Padres Enter the wins for team #1: 75 Enter team #2: Dodgers Enter the wins for team #2: 91 Enter team #3: Giants Enter the wins for team #3: 92 Enter team #4: Cubs Enter the wins for team #4: 65 League Standings: Giants: 92 Dodgers: 91 Padres: 75 Cubs: 65

Submission

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

List some guidelines to follow in planning for an interview.

Answered: 1 week ago