Question

In: Computer Science

Create a class Student (in the separate c# file but in the project’s source files folder)...

  1. Create a class Student (in the separate c# file but in the project’s source files folder) with those attributes (i.e. instance variables):

Student

Attribute

Data type

(student) id

String

firstName

String

lastName

String

courses

Array of Course objects

Student class must have 2 constructors: one default (without parameters), another with 4 parameters (for setting the instance variables listed in the above table)

In addition Student class must have setter and getter methods for the 4 instance variables, and getGPA method that calculates GPA from the courses’ grades and returns it.

Solutions

Expert Solution

using System;
//creating a class courses
public class courses
{
//declaring Subject name and mark
public string SName;
public int Mark;
}
//creating the class student
public class Student
{
//declaring variable id,firstName,lastName
//and array of courses object
string Id;
string firstName;
string lastName;
courses[] course;
//constructor with no parameter
Student()
{

}
//constructor with parameter
//setting the 4 instance variable
Student(string Id,string firstName,string lastName,courses[] course)
{
this.Id=Id;
this.firstName=firstName;
this.lastName=lastName;
this.course=course;
}
// getter method for Id
public string getId()
{
return Id;
}
// setter method for Id
public void setId(string Id)
{
this.Id = Id;
}
//getter method for firstName
public string getfirstName()
{
return firstName;
}
//setter method for firstName
public void setfirstName(string firstName)
{
this.firstName=firstName;
}
//getter method for lastName
public string getlastName()
{
return lastName;
}
//setter method for lastName
public void setlastName(string lastname)
{
this.lastName=lastName;
}
//getter method for array of course object
public courses[] getcourse()
{
return course;
}
//setter method for array of course object
public void setcourse(courses[] Course)
{
this.course=course;
}
//method to get GPA
public float getGPA()
{
//declaring and intializing
//total mark and count
int T_mark=0,count=0;
//calculating the total Mark
//counting number of mark
foreach(var item in course)
{
T_mark+=item.Mark;
count+=1;
}
//calculating GPA
float GPA=(T_mark/count);
return GPA;
}
public static void Main(string[] args)
{
//creating an array of courses class object
courses[] course=new courses[3];
//intializing the elements of courses class object
course[0]=new courses();
course[0].SName="computer";
course[0].Mark=85;
course[1]=new courses();
course[1].SName="chemistry";
course[1].Mark=70;
course[2]=new courses();
course[2].SName="physics";
course[2].Mark=75;

//creating the object student class
//constructor with no parameter
Student s1=new Student();
//constructor with 4 parameter
Student s2=new Student("s120","david","jepherson",course);
//printing the result of various getter method
Console.Write("FirstName is : ");
Console.WriteLine(s2.firstName);
Console.Write("LastName is : ");
Console.WriteLine(s2.lastName);
Console.Write("GPA is : ");
Console.WriteLine(s2.getGPA());
Console.WriteLine("Course and Marks are : ");
//getcourse return an array of courses class object
//each object is traversed by foreach loop
foreach(var item in s2.getcourse())
{
Console.Write(item.SName);
Console.Write(" : ");
Console.WriteLine(item.Mark);
}
}
}

PROGRAM FILE:-

OUTPUT:-


Related Solutions

Create a new folder called CSCI130_A3_yourname. Create all of the files indicated below within this folder....
Create a new folder called CSCI130_A3_yourname. Create all of the files indicated below within this folder. For this assignment you will be creating a total of 2 classes that meet the definitions below. This assignment will allow the user to enter in the coefficients for a polynomial function of degree 2. The user will then be asked to enter a number. The program will use that number as an argument to the function, and will print the corresponding function value....
9.6 (Rational Class) Create a class called Rational (separate the files as shown in the chapter)...
9.6 (Rational Class) Create a class called Rational (separate the files as shown in the chapter) for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class-the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
Go to the Files section and download the AFE_Test file from the Datasets folder. We are...
Go to the Files section and download the AFE_Test file from the Datasets folder. We are interested in a one­tail test described in the following fashion: Ho: u < or = to 200 CFM; H1: u > 200 CFM. At 5% significance level, we can reject the null hypothesis given the sample information in AFE_Test1. we can reject the null hypothesis given the sample information in AFE_Test2. we cannot reject the null hypothesis. we can reject the null hypothesis given...
Each of the following files in the Chapter15 folder of your downloadable student files has syntax and/or logic errors.
Each of the following files in the Chapter15 folder of your downloadable student files has syntax and/or logic errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded with Fix. For example, DebugFifteen1.java will become FixDebugFifteen1.java. a. DebugFifteen1.java b. DebugFifteen2.java c. DebugFifteen3.java d. DebugFifteen4.java    
1. What is a file? 2. What are different types of files 3. What is a folder ?
1. What is a file?2. What are different types of files3. What is a folder ?4. What is File Explorer?5. What is an address bar in FIle Explorer?6. What are the 2 main ways to open a file?7. How to move a file?8. How to create a new folder?9. How to rename a file or folder?10. How to delete a file or folder?11. How to select multiple files that are next to each other?12. How to select multiple files that...
C++ Create an ArrayBag template class from scratch. This will require you to create two files:...
C++ Create an ArrayBag template class from scratch. This will require you to create two files: ArrayBag.hpp for the interface and ArrayBag.cpp for the implementation. The ArrayBag class must contain the following protected members: static const int DEFAULT_CAPACITY = 200; // max size of items_ ItemType items_[DEFAULT_CAPACITY]; // items in the array bag int item_count_; // Current count of items in bag /** @param target to be found in items_ @return either the index target in the array items_ or...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only useiostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Create : locomotive.h, locomotive.cpp, main.cpp Locomotive Class Hierarchy Presented here will be a class diagram depicting the nature of the class hierarchy formed between a parent locomotive class and its children, the two kinds of specic trains operated. The relationship is a...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only use iostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Given : locomotive.h, locomotive.cpp, main.cpp -> https://www.chegg.com/homework-help/questions-and-answers/complete-following-task-c--separate-class-header-cpp-files-useiostream-string-sstream-crea-q39733428 Create : DieselElectric.cpp DieselElectric.h DieselElectric dieselElectric -fuelSupply:int --------------------------- +getSupply():int +setSupply(s:int):void +dieselElectric(f:int) +~dieselElectric() +generateID():string +calculateRange():double The class variables are as follows: fuelSuppply: The fuel supply of the train in terms of a number of kilolitres...
Create separate class with these members a, b, c, x, y, z int a b c...
Create separate class with these members a, b, c, x, y, z int a b c float x y z Demonstrate 3) A two arg float, int constructor, and a three arg int, float, float constructor to instantiate objects, initialize variables read from the keyboard, display the sum Note:- Please type and execute this above java program and also give the output for both problems. (Type a java program)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT