Suggested Projects

 < Day Day Up > 



  1. Word Counter: Write a program that reads a text file and counts the occurrence of each word. Print a summary of the statistics to the screen shown what word was found and its number of occurrences.

  2. Game Program: Write a game program called tic-tac-toe. The object of tic-tac-toe is to get three X’s or three O’s in a row either horizontally, vertically or diagonally. The tic-tac-toe game board is a 3 x 3 grid and looks something like this:

    During a typical game, players takes turns placing their X’s and O’s on the game board. The first to get their pattern in a row wins. The follow game board represents what the results of a typical game might look like:

    Use a 3 x 3 array to track player turns. Check the array after each player’s turn to see if they’ve won. Draw the game board on the screen after each turn so players can see the game’s progress. Make it a two player game.

  3. Quick Sort: Modify the recursive quickSort() function given in example 9.46 so it will sort in either ascending or descending order based on a callback function.

  4. Computer Simulator: You are a C++ developer with a high-tech firm engaged in contract work for the Department of Defense. You company has won the proposal to develop a proof-of-concept model for an Encrypted Instruction Set Computer Mark I. (EISCS MKI). Your job is to simulate the operation of the EISCS MKI. To do this you must write a small computer simulator *. Here are the specifications:

EISCS MKI Language Set

The only language a computer understands is its machine language instruction set, and the EISCS MKI is no different. An EISCS instruction consists of a four digit integer with the two most significant digits being the opcode and the two least significant digits being the operand. For example, the instruction 1133, as shown here,...

click to expand

...would instruct the computer to write the contents of memory location 33 to the screen. The full set of EISCS opcodes grouped by function is given below:

Input/Output Operations

READ = 10

Read an integer from the console into a specified memory location

WRITE = 11

Write an integer from specified memory location to the console

Load/Store Operations

LOAD = 20

Load an integer value from a specified memory location into the accumulator

STORE = 21

Store an integer value from the accumulator into a specified memory location

Arithmetic Operations

ADD = 30

Add an integer from a memory location to the contents of the accumulator and leave the result in the accumulator

SUB = 31

Subtract an integer from a memory location from the contents of the accumulator and leave the result in the accumulator.

MUL = 32

Multiply an integer from a memory location by the contents of the accumulator and leave the result in the accumulator.

DIV = 33

Divide the contents of the accumulator by an integer from a specified memory location. Leave the results in the accumulator.

Control/Transfer Operations

BR = 40

Branch to a specified memory location

BRN = 41

Branch to a specified memory location if the contents of the accumulator is negative

BRZ = 42

Branch to a specified memory location if the contents of the accumulator is zero.

HALT = 43

Stop program execution

Sample Program

Using the EISCS machine language instruction set above you can now write simple programs. Here is an example:

Memory Location

Instructions/ Contents

Action

00

1007

Read integer from input into memory location 07

01

1008

Read integer from input into memory location 08

02

2007

Load integer from memory location 07 into accumulator

03

3308

Divide contents of accumulator by integer from memory location 08

04

2109

Store contents of accumulator in memory location 09

05

1109

Print contents of memory location 09 to the screen

06

4010

Branch to memory location 10

07

0000

 

08

0000

 

09

0000

 

10

4300

Exit program

Basic Operation of the EISCS MKI

Memory

The machine language instructions that comprise an EISCS program must be loaded into the EISCS’s memory before they can be executed. Simulate the EISCS’s memory as an array of 100 integers.

Instruction Decoding

In order to execute programs correctly the EISCS must be able to separate opcodes from operands. Take as an example the instruction located at memory location 00 in the sample program above. the instruction 1007 must be separated into its opcode (READ) and operand (memory location 07). since the EISCS programs must be loaded into memory prior to execution the following statements might be used to extract an instruction from memory and decode it:

int instruction, op_code, operand, program_counter = 0; instruction = memory[program_counter++]; op_code = instruction / 100; operand = instruction % 100;

Additional EISCS Specifications

Allow for EISCS programs to be loaded into memory from the keyboard or read into memory from a file.

Encrypt the instruction in memory and decrypt them prior to execution by the EISCS. Use an encryption algorithm or your choice.

Write several small programs in the EISCS machine language set and run them on the EISCS.

*This project adapted from the Simpletron exercises 5.18 and 5.19 of Deitel & Deitel’s C++ How To Program, Second Edition.

  1. Assembler Program: Write a program that converts a text file containing high level EISCS commands and creates a file with EISCS machine instructions. This type of program is called an assembler. For example, the text file might contain the following instructions:

    read 07 read 08 load 07 div 08 store 09 write 09 brn 10 halt

    The assembler program would read each of these high-level instructions and convert them to their EISCS machine instruction equivalent. The machine instructions can then be loaded into the EISCS memory.

  2. Assembler Program Modified: The alternative form of the main() function is main(int argc, char * argv[]) which allows command line arguments to be read and acted upon by a program when it is first executed. The parameter argc is the argument count, or the number of command line arguments used to call the program. The parameter argv[] is an array of character strings representing the names of the command line arguments. argv[0] will always contain the name of the command that was executed. (i.e., the name of the program). Convert the assembler program written in project 5 so that the name of the input file and output file can be given as command line arguments.

  3. Explore the C and C++ Standard Library: The C and C++ Standard Library provides many useful routines you can use in your programs. Research the standard library and write a brief description of each header and the functions they contain.

  4. Scientific Calculator: Write a scientific calculator program using routines from the C++ Standard Library. Keep the interface text based and prompt the user for each operator and operand.

  5. Mortgage Calculator: Write a program that calculates the payment schedule of a 30-year, fixed-rate mortgage.

  6. Expanded Computer Simulator: Expand the EISCS MKI computer simulator to include the scientific functions you wrote for Project 8. Modify the assembler so it can generate the new machine instructions.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net