代写C代码 代做C程序 C辅导 C家教

远程写代码 Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

ARRAYS PROJECTS

 

 

Read ALL projects BEFORE any coding.  If you think ahead, you can spend

A day or two and plan a class that contains many of the methods you will

Need in this project.  Once created, the individual projects will be much easier to implement because they will all use the same (or inherited version of) class

 

1. Sum Array

 

Take a 2-D array and add up the value of the rows and the total value in the entire

Matrix along with the average number

 

You need to be able to perform this against integers and doubles

 

Example:

Array x[3][3]

Has the integer values 1 3 5

3 5 7

8 9 1

Results: Row 1 =   9

Row 2 = 15

Row 3 = 19

SUM =   43

AVG = 4.777 (must see decimals)  43/9

 

You need to write overloaded static functions, one for ints and the other for doubles.  You create the arrays in SPVM and make them each 5 ROWS by

4 COLUMNS long

 

Then ask the user for a series of integer numbers and value the array from 0,0 across the first row and continue to the next row until either the user is finished (need a sentinal) or until the entire array is filled --- YOU NEED TO CODE FOR BOTH THESE POSSIBILITIES

 

After the array is valued, call the appropriate function to get the results by passing in the appropriate array

 

THEN ask the user for a series of doubles and perform the same operation

 

HINT: you need to have a way that keeps track of  how many matrix cells were valued so the AVG is accurate as you can’t use unfilled cells with default ZEROS in the equation

 

ALSO:  try and limit any array processing to STOP early IF the remaining cells to be processed are not valued by the user

SKILLS:  2-D array processing

     Conditional loops

     I/O

     Overloaded functions

   Passing arguments

 

 

 

2. Student Grades

 

YOU MUST  SOLVE THE FOLLOWING PROJECT USING SPVM AND BY CREATING A STUDENT CLASS AND USE THAT CLASS IN SPVM

 

CREATE A GRADES.TXT FILE

 

The file is formatted as follows:

Student first name followed by 5 grades

 

Dave 89.5 99.2 100 100 100

Betty 91 100 100 98 89

 

There are a max of 25 students

 

Read in the students and their grades (an array of classes OR 2 parallel arrays)

 

Calculate the average grade for each student and create an array that holds the AVERAGE grade for each student (again, your implementation is different for a class implementation VS using static functions)

 

Once all students averages have been completed, sort the averages from lowest to highest

 

You must perform the sort TWO ways:

 

Write your own bubble sort

Use the java.util.Array’s sort method

 

Again, if you implement as a class, you job will be MUCH easier

 

Display, in order the students and their averages

 

 

 

 

3. Sort Comparison

 

Here is where you would benefit if you implemented the previous exercise as

a class

 

 

You need to take in three different types of arrays, by reading in the information from data files, and perform the following on each:

 

Sort the array using a Bubble sort AND time it

 

Sort the array using the java.util.Sort method and time it

 

Compare the times, for each type of sort, and display which sort was faster

 

The arrays need to be at least 10,000 elements each

 

CODE FOR the TIMING PART:

 

private long start=0, end=0, diff=0;

start = System.currentTimeMillis();

end = System.currentTimeMillis();

diff = end – start;

 

 

 

 

 

 

4. Reverse an Array

 

Write a program that reverses the elements of an array.

 

Allow the user to enter a set of numbers (use a sentinel value to end the input).  Then display the numbers in the order they were entered and then REVERSE the elements and display them in their reversed order.

 

For example, if the values were 1, 4, 6 , 3, and 7

 

They should end up as  7, 3, 6, 4, and 1

 

 

 

 

 

 

 

5. Tic-Tac-Toe

 

Write a program that plays a game of tic-tac-toe.

 

Again, a class would be great here as when we get into Graphics, you could reuse it

 

Use functions to process the various parts of the game (print rules, initialize the game board, user play, computer play, check for a winner, display the board, determine winner, reset the game)

 

The game will first display the rules of the game, assign the user with O and the computer with X.

 

Initialize the game board,  start the game.

 

Then iteratively,  have the user enter a value by stating the matrix position, make sure the move is valid, execute the computers play, see if anyone has won.

 

If there is a winner, let the user know and then reset the boars and ask if they wish to play another game.

 

By planning out your project on paper and separating the activities into methods, you will find it easier to complete this project.

 

 

 

 

6. NIM  (TO BE DONE AS A GRAPHIC PROJECT, Applet)

 

The game of NIM is played with 3 piles of stones.  There are 3 stones in the first pile, 5 stones in the second pile and 8 stones in the third pile.  

 

TWO players alternate taking as many stones as they like from any 1 pile.  Play continues until someone is forced to take the last stone.

 

The person taking the last stone loses.

 

 

 

 

 

 

 

 

 

7. SPELL CHECKER

 

Write your own spell checker utility.

Create a file of about 20 words.

Load that file into your program.

Ask the user to enter a word (limit them to inputting one of your 20 words)

If the word matches a word in the file, tell them the word was spelled correctly

So ask them to enter  another word or to QUIT

If the word is not in the directory, check to see if the word entered closely

matches one of  the words on file

Display the possible match

If the user says the match is correct, then ask them to enter  another word or to

QUIT

If the match is NOT what they intended, search for another possible match and

Either display that possibility or say “No Words Match” and ask

them to enter  another word or to QUIT

 

 

Example:

 

Words are:

Car

Dear

Awful

Mississippi

Default

 

User Enters:

Defalt

 

You reply:

Do you Mean Default ?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8. THE BIG  E-Z

 

Think of a range from ZERO to ONE inclusive

 

Given this range, accumulate whole fractions until their sum exceeds ONE

(.1   .2    .3    thru  .9).  Then keep track of the number of fractions required

to get a sum that exceeds 1

 

RANDOMLY GENERATE THESE FRACTIONS

 

 

For example,  .4 + .7  exceeds 1  and it took TWO fractions to do it

 

Allow for N iterations of this task

 

After executing this N times, display the AVERAGE number of fractions required

to exceed 1

 

example:

 

N = 3

 

1st .3     .2    .6      =   3 numbers

2nd .8     .3 =   2 numbers

3rd .5     .7 =    2 numbers

 

Average numbers is  2.667

 

You should run your project 1,000 times

 

ALSO,  can you identify anything special about the AVERAGE you get ?

 

ANSWER   e   or aprox 2.718

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相关推荐