How to Implement Classes in a CSI 101 Homework Assignment?

  • Thread starter Thread starter Calculus!
  • Start date Start date
  • Tags Tags
    Homework
Click For Summary
SUMMARY

This discussion focuses on implementing classes in a homework assignment for a Computer Science 101 course. The assignment requires students to define a class that encapsulates four integers, calculates their average and maximum values, and integrates this functionality into a button click event procedure. The provided code outlines the necessary steps to read integer values from text boxes, compute the average and maximum, and display the results in designated text boxes using Visual Studio or the .NET Framework.

PREREQUISITES
  • Understanding of object-oriented programming concepts, specifically classes and methods.
  • Familiarity with Visual Studio and .NET Framework for application development.
  • Knowledge of event-driven programming, particularly handling button click events.
  • Basic skills in data type conversion and string manipulation in Visual Basic.
NEXT STEPS
  • Explore class design patterns in Visual Basic to enhance code organization.
  • Learn about constructors and their role in initializing class instances.
  • Investigate error handling techniques in Visual Basic to manage user input effectively.
  • Study the use of properties in classes for better encapsulation of member data.
USEFUL FOR

Students in Computer Science courses, particularly those learning object-oriented programming, as well as educators and tutors assisting with programming assignments in Visual Basic.

Calculus!
Messages
20
Reaction score
0
Hey I need a lot of help with this homework assignment. I really have no idea of what to do. Please help me!

Write the command button Click event procedure from Homework #7 using classes. You should define the class, then write the code contained in the Click event that would use the class.

As a reminder, Homework #7 read four integers from text boxes, calculated the average and maximum value, and placed them into text boxes. Your code will do that again, but use a class. Your class will contain four integers as member data. The data must obtain the values in the text boxes, so you will need a constructor or SET function. You’ll also need two method functions, one that returns the average and one that returns the maximum value. Clearly, neither of those will require arguments.

You can create this code in Visual Studio or .NET Framework if you wish, but it isn’t necessary. I only need the code, you do not need to recreate the form.


Homework #7

'This is the code to be placed within the _Click() event of the button labeled START

'Declarations. These are needed, as you DO NOT receive any data from the arguments.
' The arguments to the Click event are set by Visual Studio options. Adding any to
' the function declaration simply means that you receive 0 values for the other arguments
Dim A As Integer, B As Integer, C As Integer, D As Integer 'The 4 integers
Dim Average As Decimal 'Must be decimal, as we want decimal places
Dim Max As Integer

'Obtain the 4 integers. Remember to convert them, as Text boxes hold Strings
A = CInt(txtNum1.Text) 'The Text property of a text box holds its value
B = CInt(txtNum2.Text)
C = CInt(txtNum3.Text)
D = CInt(txtNum4.Text)

Average = (A+B+C+D)/4
txtAverage.Text = Format(Average,”##0.00”) 'Format function isn't necessary.
'Could have used CStr function instead
'Didn't have to convert here, as Visual Studio does it for you, but it's best not
' to get comfortable with that. Not all compilers will automatically do that.

'Find maximum. Here I use a running max. I set the first number to max. I then compare
' each successive number. If the number is greater is max, I set max equal to the larger
' number. At the end, Max holds the highest value
Max = A
If B > Max Then Max = B
If C > Max Then Max = C
If D > Max Then Max = D

txtMax.Text = Cstr(Max)

Me.Refresh 'Necessary to immediate see changes to output boxes


Please Help Me! Thank you.
 
Technology news on Phys.org

Similar threads

Replies
3
Views
3K
Replies
2
Views
1K
Replies
5
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 55 ·
2
Replies
55
Views
13K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K