Programming Assignments for Scmp 218
Make sure you save your programs in your folder in P drive for each lab before the deadline. Having it elsewhere (e.g. in your H drive) does not help. Do NOT modify after the deadline.
Assignment 7, Due 11:59 pm, Thu Oct 27
Do the following programming exercises from Chapter 7 (pages 448-50)
Exercise 6: Let the user enter the number and program prints out the prime factors in descending order. Repeated factors must be printed. For example, if the input is 36, then the output should be 3 3 2 2 (or you could print it as 3^2 2^2).
Exercise 9: Read the expressions from a file and write the results to the screen. Your input file should contain all the expressions given in the problem (as sample expressions to test on page 468) but you may add more. For simplicity, you may assume that the expressions only contain uppercase letters, white spaces and the arithmetic operations +, -, * and / . (You do not have to have destructors)
Assignment 6, Due 11:59 pm, Sun Oct 16
Do programming exercise 18 at the end of chapter 6, i.e. complete the program to solve sudoku puzzles. Your program should take the input from a file. Let the user enter a file name. You can assume that the file is in the same folder as your program. Do not require the user enter the puzzle. For output, send it to both the screen and to a file. Ask for the name of the output file from the user as well.
You can assume that the file you read the input from has the right format, i.e. 81 integer values between 0-9 with 0's indicating blank spaces. Test your program with a couple of sample input files (but it should be able to read from any input file specified). Note that the description of the findEmptyGridSlot function given by the textbook (and source code) is a bit misleading. A more accurate description is: This function finds the first empty square, stores its coordinates in its arguments, and returns true. If there is no empty square, then returns false.
Assignment 5, Due 11:59 pm, Sun Oct 2
Do the programming Exercises 2,3, 6 and 17 at the end of chapter 5. Use a single test program for all functions. Use the source code from the textbook with care. If you decide to terminate the program due to the violation of a condition (e.g, position entered is larger than the size of the list) make sure that you pause the program before exiting for the user to see the error message.
Note: As given, the source code from the textbook does not compile (it used compile in older versions of C++). One solution is when a derived class (such orderedLinkedList and unorderedLinkedList) inherits from the base class linkedListType<Type> specify the type like so:
class orderedLinkedList: public linkedListType<int> as opposed to more general class orderedLinkedList: public linkedListType<Type>
There is another way to make the more general inheritance work. We will discuss this in class. If you find yet another way, let us know!
Assignment 4: Due 11:59 pm, Thu Sep 22
Do programming exercises 3, 4, 5, and 6 at the end of chapter 4. Write a single test program for all of these tasks but make sure you test each function/task separately and fully, and provide the user a good interface (that should include the option of repeating computations). Some hints:
template < class elemType>
void reverseVector(vector<elemType> &list)
typename vector<elemType> : : iterator Itr1,Itr2;
..... FILL IN THE REST
Assignment 3: Due 11:59 pm, Thu Sep15 (extended until Sunday Sep 18, midnight)
Part I: Do programming exercises 1-4 in chapter 3 (page 204-5). Write a single test program to test the functions you write. You may use the source code provided (with care).
Part II: Do programming exercise 8 (page 205). Also include the ~ operator to compute the derivative of a polynomial (see exercise 7). Write a single test program to test the functions you write. You may use the source code provided (with care) but do not assume that the source code from the textbook has the best test options. For example, you should let the user evaluate a polynomial at any complex value, not just 5.
Assignment 2: Due 11:59 pm, Thu Sep 8 (This lab is also a review from the first programming course)
Part I: is on inheritance and described here
Part II: In Programming Example of section 2, Complex numbers are implemented. Extend the definition of the class complexType given in the book by overloading the following operators:
- : for subtraction
/ : for division
~ : complex conjugation
! : absolute value
(See exercises 12-15 for more detailed description). Notice that - and / are binary operators whereas ~ and ! are unary operators.
Implement - and / as non-member operators but ~ and ! as member operators. Use the pointer this in the implementations of ~ .
You may use the files given in the book, but make sure you modify the test program so that you throughly test the new operations you define.
Part III: (For practice, not for grade) Do programming project 4 on page 125 in 2 ways: First using inheritence as described in the book. Second using composition where the class circleType includes the class pointType. You may use the test program in the class folder FILESFORLABS\Lab2 (for the inheritance version), or you can write a test program similar to it.
Assignment 1: Due 11:59 pm, Thu Sep 1 (This is a review from the first programming course)
Do programming exercises 1 and 6 at the end of chapter 1. Writing a reasonable test program with good user interface (e.g. letting the user repeat the computation) is an important part of the assignment (and this is a default requirement in all future assignments as well.). For exercise 1, you can assume that the input for Roman numeral is a legal string. Your program should allow the user to enter/test more Roman numerals than given in the text.