Write access expressions for all the element in row one of t

Assignment Help Computer Engineering
Reference no: EM131976476

Assignment

Q1. Consider a two-by-three integer array t.

a) Write a statement that declares and creates t.
b) How many rows does t have?
c) How many columns does t have?
d) How many elements does t have?
e) Write access expressions for all the elements in row 1 of t.
f) Write access expressions for all the elements in column 2 of t.
g) Write a single statement that sets the element of t in row 0 and column 1 to zero.
h) Write individual statements to initialize each element of t to zero.
i) Write a nested for statement that initializes each element of t to zero.
j) Write a nested for statement that inputs the values for the elements of t from the user.
k) Write a series of statements that determines and displays the smallest value in t.
l) Write a single printf statement that displays the elements of the first row of t.
m) Write a statement that totals the elements of the third column of t. Do not use repetition.
n) Write a series of statements that displays the contents of t in tabular format. List the column indices as headings across the top, and list the row indices at the left of each row.

Q2. (Game of Craps) Write an application that runs 1,000,000 games of craps (Fig. 6.8 of your textbook) and answer the following questions:

a) How many games are won on the first roll, second roll, ..., twentieth roll and after the twentieth roll?

b) How many games are lost on the first roll, second roll, ..., twentieth roll and after the twentieth roll?

c) What are the chances of winning at craps? [Note: You should discover that craps is one of the fairest casino games. What do you suppose this means?]

d) What is the average length of a game of craps?

e) Do the chances of winning improve with the length of the game?

Q3. (Simulation: The Tortoise and the Hare) In this problem, you'll re-create the classic race of the tortoise and the hare. You'll use random-number generation to develop a simulation of this memorable event. Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground. A clock ticks once per second. With each tick of the clock, your application should adjust the position of the animals according to the rules in Fig. Use variables to keep track of the positions of the animals (i.e., position numbers are 1-70). Start each animal at position 1 (the "starting gate"). If an animal slips left before square 1, move it back to square 1.

1551_Slippery Mountain.jpg

Generate the percentages in Fig by producing a random integer i in the range 1 ≤ i ≤10. For the tortoise, perform a "fast plod" when 1 ≤ i ≤ 5, a "slip" when 6 ≤ i ≤ 7 or a "slow plod" when 8 ≤ i ≤10. Use a similar technique to move the hare.

Begin the race by displaying BANG !!!!!

AND THEY'RE OFF !!!!!

Then, for each tick of the clock (i.e., each repetition of a loop or sleep timer-timing out every second), display a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your application should display OUCH!!! beginning at that position. All output positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank. After each line is displayed, test for whether either animal has reached or passed square

If so, display the winner and terminate the simulation. If the tortoise wins, display TORTOISE WINS!!! YAY!!! If the hare wins, display HARE WINS. YUCH. If both animals win on the same tick of the clock, you may want to favor the tortoise (the "underdog"), or you may want to display It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you're ready to run your application, assemble a group of fans to watch the race. You'll be amazed at how involved your audience gets!

Q4.

a. Create a class TicTacToe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional integer array where 1 represents X, 0 represents available/empty, -1 represents O. The constructor should initialize the board elements to empty. Allow two human players. Wherever the first player moves, place a 1 in the specified square, and place a -1 wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game has been won and whether it's a draw. If it is a win then print which player won and if it's a draw then reinitialize the array to empty and restart the game: this could be done using a sentinel controlled loop. You are provided with a class

<TicTacToePrinter> which contains a method <printBoard(int array[][])> that takes an argument of your array and prints the board. Use this method to print the board after every move.

b. Feeling ambitious, modify your program so that the computer makes the moves for one of the players. Also, allow the player to specify whether he or she wants to go first or second. Use an enumeration to represent the value in each cell of the array. The enumeration's constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Wherever the first player moves, place an X in the specified square, and place an O wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game has been won and whether it's a draw. If it is a win then print which player won and if it's a draw then reinitialize the array to empty and restart the game: this could be done using a sentinel controlled loop. You are provided with a class <TicTacToePrinter> which contains a method <printBoard(int array[][])> that takes an argument of your array and prints the board. Use this method to print the board after every move. If your original array is enum type then you would need to convert it into integer and then use this method.

Q5. Write a method that reverses the order of elements in an ArrayList<E> without creating a new ArrayList. You may only use the methods remove, add, and size. (For this problem you could use ArrayList<Integer> or ArrayList<String>). Write a driver class and demonstrate the working of your method.

Q6. Derive a class Lizard from Reptile (Reptile & Vertebrate is provided to you) with private data members as int lizardLength, String lizardLocation. (lizardLocation values could be tropical, dry, cold etc.). Add a 4 argument constructor in this class to initialize values of brainSize, eggSize, lizardLength & lizardLocation. Override the toString method in this class and make it return all the 4 data members as String. Create a main method inside this class and create an object by initializing values for member data. Print this object using toString() method. Output shall look like:

brain size = 0.9 egg size = 4.0 lizardLength = 10
lizardLocation = tropical

Q7. Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. You are being provided with a Point class, use it to represent the points in each shape. For e.g. the private instance variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. Write a program that instantiates objects of your classes and outputs each object's area (except Quadrilateral).

Quadrilateral:

Data: Point topLeft, topRight, bottomLeft, bottomRight; Methods: Constructors, getters, setters, toString

All derived classes: Each derived class must have its own instance data like side for Square, length & width for Rectange and so on.

Methods: Constructors, setters, getters, to String, get Area() Instructions.

Reference no: EM131976476

Questions Cloud

Complete the theories of behavior timeline worksheet : This assignment helps you get an idea of the foundation that was created for ABA, including who the theorists were, what they did, and with when they did it.
Prepare the april and june entries for flounder : Flounder Mining Company declared, on April 20, a dividend of $442,000 payable on June 1. Prepare the April 20 and June 1 entries for Flounder
Determine the enthalpy of neutralization of the reaction : Determine the enthalpy of neutralization of the reaction. 2NaOH(aq) + H2SO4(aq) Na2SO4(aq) + 2H2O(l) Assume the volumes are additive
Prepare carla journal entries to record transactions : Carla Corporation has outstanding 20,000 shares of $5 par value common stock. Prepare Carla's journal entries to record these transactions using the cost method
Write access expressions for all the element in row one of t : Write access expressions for all the elements in row 1 of t. Write a nested for statement that initializes each element of t to zero.
How much was microtel net income : The only other transaction during 20X6 was the purchase of $5,000 of equipment for cash near the end of the year. How much was Microtel's 20X6 net income
Concentration of a solution : What is the mass percent (m/m) concentration of a solution of 17.0 g of sodium chloride in 233. g of solution?
Conduct external and internal audit : Develop alternate solutions to solve problem or to capitalize on opportunities. You can use any 3 of the 5 tools to develop alternate strategic solutions.
Determine whether each of joint products should be sold : Kirk Minerals processes materials extracted from mines. Determine whether each of the three joint products should be sold as is, or processed further

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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