Homework Assignments

Homework 3

Homework 3

Due by Frebruary 12, 2010 - 11:59pm

Homework 2

Q1: Is it possible to place eight queens on an empty chessboard so that no queen is "attacking" any other, i.e., no two queens are in the same row, the same column, or along the same diagonal? Write a program that displays a chessboard (8 rows x 8 columns), and labels the position of each queen.

To approach this problem, you should implement a ChessBoard class. This class should contain a private, 2D character array named board. This 2D array should be dynamically allocated upon construction of a ChessBoard object. The size of the board should be 8 rows x 8 columns.

The formal parameter list of the ChessBoard constructor should contain all necessary parameters needed to specify an inital position (row and column) for a single queen. If no position is specified, the values should default to position (0,0).

The ChessBoard class should also contain a solve function. This solve function will attempt to find a solution to the 8-Queen problem with one queen located at a user-specified location.

Your ChessBoard class should contain a printSolution function that outputs one of the following:

A message stating that a solution can not be found, or

An ASCII drawing to the console illustrating the position of each queen.

Your program should use pointers to access any and all array elements. Furthermore, all arrays should be created dynamically, and deleted when done.

Organize your code by separating the ChessBoard class definition from it's implementation. The definition should be defined in a ChessBoard.h header file, and the implementation should be contained in a ChessBoard.cpp file. Your main function should be contained in an EightQueens.cpp file. This file should include all required libraries, including your ChessBoard.h file.

(25 pts) ChessBoard header and source files
(40 pts) ChessBoard implementation
(60 pts) Solve the 8-queens problem given the user's input
(25 pts) Display the output in an intuative, easy-to-read manner

Total: 150pts

Due by January 29, 2010 - 11:59pm

Homework 1

A bookstore keeps a file of transactions, each of which records the sale of a given book. Each transaction contains an ISBN (International Standard Book Number, a unique identifier assigned to most books published throughout the world), the number of copies sold, and the price at which each copy was sold. Each transaction looks like

0-201-70354-X    4    24.99

where the first element is the ISBN, the second is the number of books sold, and the last is the sales price. Periodically the bookstore owner reads this file and computes the number of copies of each title sold, the total revenue from that book, and the average sales price. In this assignment you will develop a C++ program that will perform these computations automatically.

Your program should utilize the Sales_item class defined in Sales_item.h. It should also read in multiple transactions, grouped together by ISBN, and report the ISBN, number of copies sold, total revenue from book, and the average sales price.

Sample Input

0-201-70354-X     3     20.00
0-201-70354-X     2     25.00
0-201-72148-1     4     55.00
0-201-72148-1     2     60.00
0-201-72148-1     3     57.00
0-13-208494-5     7     70.00
0-13-208494-5     5     82.00

Expected Output

0-201-70354-X     5     110     22
0-201-72148-1     9     511     56.78
0-13-208494-5    12     900     75

All source (.cpp) and header (.h) files must be uploaded to CSNS to receive credit for the assignment. Be prepared to demo your program on Tuesday, January 12, 2010.

Due by January 12, 2010 - 8:30am

Announcements

CSNS All files must be submitted to CSNS prior to the due date/time.