Question: This is a C# Exercise 2.3 Class Student Declare a class Student with some private data members as follows. private string name; private int id;
This is a C# Exercise
2.3 Class "Student" Declare a class "Student" with some private data members as follows. private string name; private int id; private double GPA; private string[] courses; private int numCourses; Write a public class constructor to set input values for the name, id and GPA. 1. For simplicity, we assume a student takes 3 courses hence initialize numCourses = 3. 2. Allocate courses to an array of length numCourses (use operator new). 3. If the input for the GPA is negative, set GPA=0. The data members name and id are read only: write getters but no setters for them. Write both a getter and a setter for the data member GPA. The setter should not allow the value of GPA to be set to a negative value. Write a public method string getCourse(int n). 1. If n numCourses, do nothing. 2. Else assign course [n] - s. Write a public method void setCourses (string[] cs) to set all the courses. Write a public method void print(). 1. Print the values of the name, id and GPA to the console. 2. Write a loop to print the courses the student is taking. Write a main program to instantiate a few Student objects. 1. Invoke all the various class methods in your program. 2. In particular, assign various courses for each student. 3. Verify that the class methods work correctly if bad inputs are supplied. 4. Invoke set GPA to change the GPA and invoke getGPA and print the updated value. Write and test a function "swap" to swap two Student objects. 1. The inputs to swap must be passed by reference. 2. Swap some Student objects in your main program and print before/after results
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
