Program Assignments for CSC
275
Spring 2005
Program 1: Using EZWindows write a C++ program that:
a. Displays an ellipse, circle, triangle, rectangle, and square with a different fill color for each shape.
b. Displays the name of each shape over the shape with the font color the same as the fill color for that shape and a different background color for the text.
Program 2: Modify EZWindows program
Modify the stock program from Chapter 6 to include:
a. All numbers on both axis
b. Add a check for invalid data (first number for week cannot be greater than or equal to second number) and display “Bad data for week” instead of bar.
The original program is in the Course Material directory under stocks subdirectory.
Program 3: Use EzWindows to draw a sine graph
Using prog4-12.cpp as an example, write a program to read values from file sine.txt (this file is in \CSC275\Course Material\ExamplePrograms). Apply the values in sine.txt to the sine function and chart the output using EzWindows and rectangles as the points. The program prog4-12.cpp is in
\CSC275\Course Material\ExamplePrograms. data.txt is the input file for that program.
Program 4: Fibonacci
Sequence (Array application)
A Fibonacci sequence is a numerical sequence such that after the second element all numbers are equal to the sum of the previous two elements.
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Write a program to calculate and print the first 20 elements of this sequence.
Program 5: Statistical Functions
Design and implement the following statistical functions. Each of the functions returns a float value and has two parameters: A and n. Parameter A is an array of float objects; parameter n is the size of array.
a. Function Mean(): it returns the average of the n values in the list.
b. Function Median(): it returns the middle value of the n values in the list if n is odd; it returns the average of the two middle values of the n values in the list if n is even.
Program 6: Matrix Product
Given a matrix A with m rows and n columns and a matrix B with n rows and p columns, we can compute the product matrix C = AB. The product C has m rows and p columns where element Cij has the following definition:

Write a program to implement this.
Program 8: Screen Saver
Write an EzWindows program that simulates a screen saver. The program opens a window that is as large as the screen and displays a bitmap of your choice at random locations within the window. It draws the bit map at a new location at a random time interval between 2 and 6 seconds.
Program 9: Grades and Weighted Averages
Write a program that computes final averages for a set of grades. The program reads the grades from a file called scores.dat (that file will be in the folder class files under csc275). The file scores.dat begins with a header line followed by a set of scores for each student. The format of the header line is
n weight1 weight2 … weightn
where n is the number of scores for each student and weighti is the weight of the ith score.. The header line is followed by grades for each student. The format of a grade line is
name score1 score2 … scoren
where name is the last name of the student and scorei is the ith score. Each score is separated by a tab (“\t”) and the scores for a student end with a newline (“\n”). All scores must be between 0 and 100.
The program reads the file scores.dat and writes a file called average.txt that has the following format:
name score1 score2 … scoren => nn.nn Average (Letter)
where name and scorei are as before and nn.nn is the weighted average of the student’s scores. Letter is a letter grade based on the table to follow. The weighted average is computed as

The letter grade is based on the table:
|
Average |
Letter Grade |
|
0-59 |
F |
|
60-69 |
D |
|
70-79 |
C |
|
80-89 |
B |
|
90-100 |
A |
The final output the average.txt is the overall class average.
Your program should validate its input. That is, it should make sure each score is between 0 and 100 and that each student has n scores. If a student’s scores are invalid, the program should write an error message to the output file average.txt.
Program 10: Add StarShape to EzWindows
Create a class called StarShape for drawing stars in a window. Class StarShape should be derived from the class Shape. A star can be rendered using SimpleWindow’s RenderPolygon member function. A StarShape has the characteristics shown in the following diagram:

The position of the star is specified by giving the coordinates of its center. The size of a star is specified by giving the length (in centimeters) of the distance across the star. Demonstrate the use of StarShape by writing a program that draws six stars in a window. The stars should have the following colors: red, blue, green, yellow, cyan, and magenta.