Current Semester
Spring 2009
YU Links
Prior Semesters
Fall 2008
Spring 2008
Fall 2007
Spring 2007
Fall 2006
Spring 2006
Fall 2005
Fall 2002 - Spring 2005

INF3835: Advanced Visual Basic - (Homework)

HW #,due date Assignment
HW#1
Due: Wednesday Jan 17, 2007

Submit the following to Angel


Write a program that uses nested loops to display the following picture. The picture should be a 4 by 3 rectangle composed of X's as shown below.

     XXXX
     XXXX
     XXXX

Write a program that uses nested loops to display the following picture. The picture should be a triangle composed of X's in the configuration shown below.

     X
     XX
     XXX

Write a program that uses nested loops to display the following picture. The picture should be a triangle composed of X's in the configuration shown below.

        X
       XX
      XXX
     XXXX

Write a program that uses nested loops to display the following picture. The picture should be a triangle composed of X's in the configuration shown below.

     XXXXX
      XXXX
       XXX
        XX
         X

Write a program that uses a loop to compute the sum of the numbers from 1 through 5 (ie. 1+2+3+4+5 which is 15). The program should "figure out" the answer - DO NOT have the program just display the number 15 without using a loop to figure it out. Write your program so that you can easily change the program to compute the sum of the numbers from 1 through 100 or from 1 through any number by just changing the number 5 in your code to the new number.


Write a program that uses a loop to compute the sum of the the factorials of the numbers from 1 through 5 (ie. 1!+2!+3!+4!+5! ) as in the following mathematical notation:

(Click here for the definition of a factorial)

The program should "figure out" the answer - DO NOT have the program just display the answer without using a loop to figure it out. Write your program so that you can easily change the program to compute the sum of the factorials from 1! through 7! or from 1! through the factorial of any number by just changing the number 5 in your code to the new number.


Write a program that uses a loop to compute the sum of the values

n! * (n-1)!

where n varies from 1 through 5. (ie. 1!*0!+2!*1!+3!*2!+4!*3!+5!*4! ) as in the following mathematical notation:

(Click here for the definition of a factorial)

The program should "figure out" the answer - DO NOT have the program just display the answer without using a loop to figure it out.

This value can get VERY large as n gets large. You may only be able to run your program for very small values of n (e.g. 1,2,3,4).


HW#2
Due: Monday Jan 22, 2007

Study the code for the following program. Make sure that you understand the code. The zip file below contains the entire folder for the program. To run and modify the program, download the zip file, unzip it and double click on the .sln file to load it into VB Express 2005. To just view the code you can look at the Module1.vb file. You do not have to modify the program, but please come in Monday understaning it fully.


HW#3a
Due: Wednesday Jan 24, 2007

Submit the following to Angel


Write a program that asks the user to enter a list of numbers (Integers). The user indicates that he is finished entering numbers when he enters the letter "q" (i.e. quit) instead of a number. When the user is finished, the program should display the following information:

  1. largest number from the list
  2. smallest number from the list
  3. the average (i.e. mean) of all the numbers in the list
  4. the sum of all the numbers in the list
  5. the product of all the numbers in the list
  6. the "variance" of the list
    (see the following URL for a defintion of variance and standard deviation: http://davidmlane.com/hyperstat/A16252.html
  7. the "standard deviation" for the list - standard deviation is the square root of the variance - the built in function, Math.Sqrt(Double) as Double , takes a Double parameter and returns the square root of the parameter.
HW#3b
Due: Monday Jan 29, 2007

Submit the following to Angel


Description of problem

A professor needs a program to help him grade tests. Write a program that asks the user to enter the grades for a test. For each test, the user should be prompted to enter the first name, last name and test score for each student. Your program should store the user's entries in 3 different parallel arrays - one for first name, one for last name and one for the test score. The user should indicate that he is finished entering grades for the class by typing the letter "q". When the user finishes typing in the data, the program will show the results listed below. The program will automatically determine a curve, if necessary, and will display some statistics about the test both before an after applying the curve.

Implementation

Your program should contain and use the following functions. Each function should take the appropriate parameters and return a n appropriate result.:

  • sum - returns the sum of all the values in an array
  • highest - returns the highest number from an array of numbers
  • lowest - returns the lowest number from an array of numbers

Results

The program should display the following results

  1. The program should print out "*** RESULTS ***" followed by the following information.
  2. The test score and student names for all students who got the highest grade in the class. If more than one student tied for the highest grade, the program should display ALL students who got that grade.
  3. The average score for the class counting all grades
  4. A list of the names and scores for all students who scored below average (not counting the highest and lowest scores)
  5. The average score for the class not counting the highest and lowest scores. - If more than one student tied for the highest or lowest grades then the calculation should ignore just one copy of the highest and one copy of the lowest grades from the average. For example if there were 6 students in the class and the grades were:
    • 30 - Joe Smith
    • 70 - Bill Cohen
    • 75 - John Doe
    • 85 - Sam Spade
    • 90 - Jack Smith
    • 90 - Robert Rothenberger
    then average not counting the highest and lowest grade should be (70+75+85+90)/4 = 80. Note that the lowest grade, 30, and just one copy of the highest grade, 90, were eliminated from the calculation of the average. You can calculate this sum in your program by using the sum function to calculate the sum of ALL scores. Then subtract from that total the number for the lowest and highest grades - determined using the lowest and highest functions.
  6. Your program should automatically calculate a curve. If the average grade, not counting the highest and lowest scores, is less than 85, then the program should add whatever number is necessary to all test scores to bring the average up to 85. Your program should then display the number of points it calculated for the curve. If no curve was necessary then the program should just display the words - "*** NO CURVE NECESSARY ***".
  7. Display the "*** SCORES ***" followed by the list of scores. If there was a curve then display the curved scores.

SAMPLE OUTPUT

First Name: Joe
Last Name: Smith
Score: 30

First Name: John
Last Name: Doe
Score: 75

First Name: Jack
Last Name: Smith
Score: 90

First Name: Sam
Last Name: Spade
Score: 85

First Name: Robert
Last Name: Rothenberger
Score: 90

First Name: Bill
Last Name: Cohen
Score: 70

First Name: q

*** RESULTS ***

Highest Score: 90
Sudents who got the highest score:
  Jack Smith
  Robert Rothenberger

Average (counting all grades):  73.3333

Students who scored below average:
  Joe Smith
  Bill Cohen

Average (not counting the highest and lowest grade): 80

Curve: 5

*** SCORES ***
Joe Smith 35
John Doe 80
Jack Smith 95
Sam Spade 90
Robert Rothenberger 95
Bill Cohen 75
HW#4
Due: Monday Jan 29, 2007

Submit the following to Angel


ABOUT PRIME NUMBERS

A prime number is a number that is divisible by only 1 and itself. For example, the numbers 1, 2, 3, 5, 7, 11 are all examples of prime numbers. However, 4 and 6 are NOT prime since they are divisible by 2. The number 9 is also NOT prime since it is divisible by 3.

To determine if a number, N, is prime it is not strictly necessary to check if N is divible by every number below it. Rather, mathematically, it can be proven (we won't show the proof here) that N is prime if and only if it cannot be divided evenly by any prime number (other than 1) which is less than N. For example:

  • To determine if 19 is a prime number it is sufficient to check if 19 is divisible by any prime number less than 19 (assuming that I have a list of those numbers). Specifically because 19 is not divisible by 2,3,5,7,11,13 or 17 (i.e. all the prime numbers less than 49 - other than 1) we can safely say that 19 is a prime number.

  • To determine if 49 is a prime number it is sufficient to check if 49 is divisible by any prime number less than 49 (other than 1). Let's check each prime number starting from 2 and see if 49 is divisible by any of those prime nubmers.

    • Is 49 divisible by 2? - no
    • Is 49 divisible by 3? - no
    • Is 49 divisible by 5? - no
    • Is 49 divisible by 7? - YES (we can stop here)

    Since 49 is divisible by 7, 49 IS NOTa prime number.

THE ASSIGNMENT

Write a program that figures out and displays the first 100 prime numbers (i.e. 1,2,3,5,7,11,13,15,19,......). Your program should calculate the primes one at a time starting from the lowest numbers. As each prime is calculated it should be stored in an array that contains all primes that your program has calculated so far. When your program tries to calculate what the next prime number is it should check to see whether or not the number it is examining is divisible by all of the primes that the program has calculated so far. Using an array to remember all primes calculated so far makes the program to calculate 100 primes much more efficient than if you would not use an array.

HW#5
Due: Wednesday Jan 31, 2007

Finish the following project for next class. Bring your code in to class. We will be building on this some more. You do not have to submit this project yet. However, you will be asked to submit it later after we have built it up some more.


ASCII ART

The following "picture" was created using "regular" characters. This kind of picutre is sometimes referred to as ASCII art:

    ....................
    ....................
    ........HHH.........
    ........HHH.........
    ........HHH.........
    .........|..........
    .........|..........
    ...AAAABBBBBAAAA....
    ...AAAABBBBBAAAA....
    ...AA..BBBBB..AA....
    ...AA..BBBBB..AA....
    ...AA..BBBBB..AA....
    .......LL.LL........
    .......LL.LL........
    .......LL.LL........
    .......LL.LL........
    .....FFFF.FFFF......
    .....FFFF.FFFF......
    ....................
    ....................
THE ASSIGNMENT

Write a program that creates ASCII art. Your program should use a two dimensional array to store the characters that make up the picture. Your program should contain the following subs:

Sub ErasePicture()
This subroutine fills the entire 2d array with spaces (or periods)
Sub DrawRectangle(startRow as Integer, startCol as Integer, width as Integer, height as Integer, penColor as Char)
This sub draws a rectangle of specific dimensions of a specific character (i.e. penColor) at a specific location in the array.
Sub DisplayPicture()
This sub displys the picture on the screen.

You should create and display a picture from the Main() sub by making appropriate calls to the subroutines mentioned above.

HW#6
Due: Mon Feb 5, 2007

Finish the following project for next class. Bring your code in to class. We will be building on this some more. You do not have to submit this project yet. However, you will be asked to submit it later after we have built it up some more.


Slope and The Formula of a Line

Given two points on a line, (i.e. x1,y1 and x2,y2) the slope of the line, m, is defined as (y1-y2)/(x1-x2).

EXAMPLE: If a line contains the two points 1,2 and 3,4 (i.e. x1=1, y1=2 and x2=3, y2=4) we can determine the slope of the line as :
m=(2-4)/(1-3) which is equal to -2/-2 which is equal to 1.

One form of the mathematical formula for a line is : y = m(x - x1) + y1 Where x1,y1 is a specific point on the line and m is the slope of the line. Using this equation, if you know a specific point on the line and you also know the slope you can choose any x value for a point on the line and using the formula figure out the y value for that point.

EXAMPLE: Given a line which contains the point 0,0 and has a slope of 2. If you choose a specific x value for a point on this line you can figure out the y location for that point using the equation listed above. For example the y value for the point on the line with an x value of 1 is:
y=m(x-x1)+y1 By substituting the values that we know for m, x1, y1 and x we get the following:
y=2(1-0)+0 from this we get y=2 so the point on the line would be (1,4). If instead we chose the point on the line with an x value of 2 we would get:
y=2(2-0)+0 or y=4 so the point on the line would be (2,4)
THE ASSIGNMENT

The following is a continuation of the project that creates ASCII art.

Add the following subroutines to your program

sub drawLine(ByVal penColor as Char, ByVal startX as Integer, ByVal startY as Integer, ByVal endX as Integer, ByVal endY as Integer)
This sub draws a line in the 2d array. The line starts at coordinates (startX,startY) and ends at coordinates (endX,endY). The sub first calculates the slope of the line using the two specified points. The slope should be saved in a Double variable. The coordinates of the line are calculated by starting with the X value for one point and looping through to the X value for the other point. For each time through the loop, the associated value of Y is calculated. The value for Y should initially be calculated as a Double and then converted into an Integer by rounding the value using the Math.Round method. The calculated point X,Y is then plotted in the array as a point on the line.
Sub DrawEmptyRectangle(penColor as Char, startRow as Integer, startCol as Integer, width as Integer, height as Integer, borderWidth as Integer)
This sub draws a rectangle of specific dimensions using a specific character (i.e. penColor) at a specific location in the array. Only the border of the rectangle should be drawn. The pixels inside the rectangle should NOT be changed from what they were before. The borderWidth parameter indicates how "thick" the border should be.
HW#7
Due: Mon Feb 12, 2007

Bring your code in to class. We will be building on this some more. You do not have to submit this project yet. However, you will be asked to submit it later after we have built it up some more. NOTE: I added the menu choices to Draw a rectangle, draw an empty rectangle and Exit. You do not have to do all this for next class. As I mentioned, I am not asking for you to submit this yet. However, you will be expected to have these options later when I do ask you to submit the program.


THE ASSIGNMENT

In this assignment you will continue to develop the ASCII art program.

The program will be modified to be able to create and display several different pictures. Your program should maintain an array of pictures. The following code can be used to declare a one dimensional array that holds 100 two dimensional arrays:

Dim pics as Char() (,) = New Char (100)(,) {}

To create a specific 2d arrays you can use code similar to the following. The following code creates a 2d array of 20 by 30 in the first slot of the array of pictures. It then creates a 2d array of 10 by 10 in the 2nd slot of the array of pictures.

pics(0) = New Char(20,30) {}
pics(1) = New Char(10,10) {}

Modify your program so that each sub that works with a picture will take as its first parameter a 2 dimensional array. For example to draw a line the program should have the following sub:

Sub DrawLine(ByVal pic as Char(,), ByVal penColor as Char, ByVal x1 as Integer, ByVal y1 as Integer, ByVal x2 as Integer, ByVal y2 as Integer)

This first parameter allows the caller to specify in which picture the line should be drawn. For example the following code will draw a line made out of x's in the 2nd picture (i.e. index 1) but not in the first picture (index 0).

DrawLine(pics(1),'x',0,0,9,9)

Your program should display the following menu to the user:

Make a choice
1. Create a new picture
2. Select a picture
3. Draw a line
4. Draw a rectangle
5. Draw an empty rectangle
6. Exit
choice:

The following explains what the program should do when the user chooses each option

1. Create a new picture
The program should prompt the user to specify the dimensions of the new picture. The program should then create a "New" 2d array and assign it to the next free slot in the array of pictures. The program should then fill the new picture with periods. The program should then display the new picture (i.e. it will just contain periods). The new picture becomes the "Selected Picture" (see next choices)
2. Select picture
The program should prompt the user for the number of the picture to select. The picture that the user chooses must already exist (if it doesn't tell the user so). The program should then display the specified picture. This picture now becomes the "Selected Picture". Any drawing that is done in the future should be done to the "Selected Picture"
3. Draw a line
The program should prompt the user for the penColor and the x,y values of the two endpoints of the line. The program should then draw the line into the currently "Selected Picture" and display that picture.
4. Draw a rectangle
The program should prompt the user for the penColor and the x,y values of the upper left hand corner of the rectangle and the height and width of the rectangle. The program should then draw the rectangle into the currently "Selected Picture" and display that picture.
5. Draw an empty rectangle
The program should prompt the user for the penColor and the x,y values of the upper left hand corner of the rectangle, the height and width of the rectangl and the border width. The program should then draw the empty rectangle into the currently "Selected Picture" and display that picture.
5. Exit
Exit the program.
HW#8
Due: Wed March 14, 2007

Implement the classes that are shown in the following class diagram. Click on one of the links below to see the diagram. All the links show the same diagram (in different formats).

HW#9
Exception Classes (click to see the assignment)
HW#10
Creating and using a .dll (click to see the assignment)
HW#11
VectorCanvas (click to see the assignment)
HW#12
Reading a file (click to see the assignment)
HW#13
Saving a VectorCanvas in a file (click to see the assignment)