Write recursive functions that perform insertion

Assignment Help C/C++ Programming
Reference no: EM131065442

Directions: The problems in this assignment are full programming problems. For each program, submit your source code and project files. When adding files to your zip file use folders to keep projects separate. Remember to keep a copy of your work.

1. Write recursive functions that perform insertion and retrieval operations on a pointer-based sorted linked list of integers. The insertion function should be void, taking a head pointer and the item to be inserted as parameters. The retrieval function should take a head pointer and the item to be retrieved as parameters, and should return the item's position, or -1 if the item is not found in the list. Use these procedures to write a program that inputs a series of integers, inserting them into a list until 0 is entered. Then a second series of integers is input, until 0 is entered, and the position of each integer in the list is displayed. Example:

Enter numbers to be inserted (0 to end): 34 23 1 45 7 0
The list is: 1 7 23 34 45
Enter numbers to be retrieved (0 to end): 23 8 45 0
23 is at position 3
8 is not in the list
45 is at position 5

Note that the program should be able to handle requests to retrieve items that are not in the list.

2. Create a class called Board for use in playing the game tic-tac-toe. Recall that the game is played on a 3 x 3 board, where every square is either empty, or contains an "X" or an "O." The game is won when there are three X's or three O's in a straight line, either in the same column, the same row, or one of the two diagonals. The game is a stalemate when the board has no empty squares but neither X nor O has won.

The following includes references to an enumerated type Player, defined as:
enum Player {X, O, empty};

Your class should have the following public methods:

Board: (constructor) This initializes the board, which means it sets all the positions to empty and does all else necessary to make the board ready for use.

void Place(P, Column, Row): A procedure that takes a Player P and sets the Column and Row of the board to be Player P if that position is empty.

If the position is occupied, the player loses a turn.

bool Win(P): A function that returns true if Player P has won the game, and false otherwise.
bool Stalemate(): A function that returns true if the board represents a game in stalemate, and false otherwise.

You do not have to write a complete program that plays the game. However, you are to write a short program that adequately tests all the operations of your class. Notice that the earliest either player can win is after 5 plays.

3. An integer can be represented by a linked list with one digit in each node. The least significant digit in this representation is in the first node of the list. This allows for integers of virtually any size. The nodes are of the following type:

struct digit
{ int Value; // a digit value, 0-9
digit* Next;
};

typedef digit* ptrType;

The following diagram shows the representation for 2149:

1604_java.png

 

Develop an ADT named number with the following operations for unlimited-digit numbers. In the following descriptions, number refers to an object of your ADT. M, N and O are all of type number. The sample usage for each operation shows how it might be used, although you can make your operations work differently.

Increment: A method that increases the value of a number by 1. Sample usage: N.Increment();

Note that you cannot necessarily just change the last digit of the number; adding 1 to 1999, for example, requires changing all four digits to get 2000, and adding 1 to 9 requires making a new digit to get 10.

Hint: You should allow for three possibilities in your function regarding the initial value for N.

a. N is NULL
b. N is not NULL, and the value in the first node is 0..8
c. N is not NULL, and the value in the first node is 9

Copy: A method that copies one number to another. Note that you cannot just copy one pointer to another - you must create copies of each node in the original as illustrated in a copy constructor for linked lists. Sample usage: N.Copy(M);

Sum: A method that takes two numbers and sums them. Sample usage: N.Sum(M); (adds M to N). Don't forget about a carry when the sum of two digits is greater than 10.

Display Number: A method that displays the number in standard (most-significant digit first) form. Sample usage: N.DisplayNumber();

Your ADT should be a C++ class, with all functions and data declared in the appropriate sections. You may use recursion as you wish. Include a short program that adequately tests all the procedures in your ADT.

Reference no: EM131065442

Questions Cloud

Examine issue that may occur during hr planning process : From the scenario, select a country then examine an issue that may occur during the HR planning process when employees are transferred to work as expatriates. Provide the solution to the issue
Show me the code whereby after user has inserted : I need someone to create a form using notepad ++ and show me the code whereby after user has inserted his/her details from the form you can get the details from the database.
Analyzing an article to evaluate how effectively the author : In this discussion assignment, you will be analyzing an article to evaluate how effectively the author has managed to convey his or her point of view.
Define an ethical issue that you either encountered : Define an ethical issue that you either encountered or studied in a previous course (you cannot use prior papers to fulfill this assignment)
Write recursive functions that perform insertion : Create a class called Board for use in playing the game tic-tac-toe. Recall that the game is played on a 3 x 3 board, where every square is either empty, or contains an "X" or an "O." The game is won when there are three X's or three O's in a st..
Use a give pattern of development - compare and contrast : Paragraph Assignment Three will be based on prompts to one of two readings. The prompts will also indicate specific rhetorical modes (patterns of development) to be used in the responses. Choose one of the two suggestions.
How is your behavior as a consumer consistent : How is your behavior as a consumer consistent with the selected primary and secondary group classification descriptions
Can such a system have a unique solution explain : Can such a system have a unique solution? Explain.
What other consumer promotions could be used : How would you organize a sampling program in light of these cultural factors? What other consumer promotions could be used? If you have someone in your class from a Muslim country, ask your classmate to discuss the use of consumer promotions in his ..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Expand the "currency conversion" program to include a menu

Expand the "Currency Conversion" program to include a menu that allows the user to choose which currency he/she wishes to display in its equivalency to the US dollar. - Correctly use at least 1 function or subroutine

  Prepare a program to add the specific numbers

Write a program that will read in 5 numbers and add 10 to the first number, 20 to the second number, and 30 to the third number, 40 to the fourth and 50 to the 50th.

  Write a while loop that lets the user enter a number

Write a while loop that lets the user enter a number-The number should be multiplied by 10, and the result stored in the variable product

  Write a program that calculates the average rainfall

Write a program that asks the user to enter five floating-point numbers. The program should create a file and save all five numbers to the file.

  Your project must use and demonstrate understanding

Your project must use and demonstrate understanding of:a. Variables b. Loops c. Decision statements d. File I/O e. Screen output f. Keyboard input g. Functions h. Arrays i. Searching and sorting j. Classes k. Objects l. Methods

  Explain the data types used in c language

What is data type? Explain the data types used in C language.Write a program and draw a flowchart to print 1 to 100 all natural numbers.

  Least number of comparisons needed

What is the least number of comparisons needed to sort an array of 6 numbers, in the worst case, using any sorting algorithm that sorts with binary comparisons? Explain

  Create a bar chart showing the average monthly mean temperat

Write a ++ program to create a bar chart showing the average monthly mean temperature for College Station from 2004 to 2013. The point of the exercise is to compute the sie and location of the rectangles rather than explicitely hardcode that informat..

  Create a friend class

Create a Friend class that contains a first name, last name, a birthday, and a telephone number. Create a Contacts class that contains an array of Friend as well as the owner's name and cell phone Number.

  Program that opens a file representing an encoded maze

Write a C++ program that opens a file representing an encoded maze and reads it in properly so it can be analyzed.

  Calculate the cube of a number

Write a program that will calculate the cube of a number. Do this by writing a user defined function that returns the cube of the value passed to it. Print out the results from main.

  Dynamically allocates an array large enough

Write a program that dynamically allocates an array large enough to hold a number of test score. The size of the array should be input by the user

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd