0% found this document useful (0 votes)
59 views4 pages

LAB 4 - DCE Ali

1. The document discusses creating classes in C# for a Student class and a main class. 2. The Student class defines private variables for name, registration number, degree, and GPA. Getter and setter methods are added for each variable. 3. A main class is created to initialize a Student object and call the getter methods to output the student's information.

Uploaded by

400b
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views4 pages

LAB 4 - DCE Ali

1. The document discusses creating classes in C# for a Student class and a main class. 2. The Student class defines private variables for name, registration number, degree, and GPA. Getter and setter methods are added for each variable. 3. A main class is created to initialize a Student object and call the getter methods to output the student's information.

Uploaded by

400b
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DCE Prepared by Natalia Ahmed Question#1 ref lab 3

IBIT

Lab4

Create a class Student and declare private variables Name, regNumber, degree of type string and cgpa of type float. Write a constructor function for student which takes values from user. Create another class for main function and create object of type student. {Constructor ko bar bar call nai ke sakte Ye reentry ha .ye fun change kare ga . get function return kerwae gaye sare class me likhne hain or main me object ke sath karine hain}
using System; using System.Collections.Generic; //using System.Linq; using System.Text; namespace Project1 { class student { public void setname() { name= Console.ReadLine(); public void setregname() regname= Console.ReadLine(); public void setdegree() degree = Console.ReadLine() public void setcgpa()

Additions 1. 2. 3. 4. 5. Add getter and setter functions for name Add getter and setter functions for regNumber Add getter and setter function for degree Add getter and setter function for cgpa Add a function that prints all the information of object on console.

DCE Prepared by Natalia Ahmed

IBIT

Lab4

Question # 2 Inheritance Implement Base Classes. Implement Derived Classes. Initialize Base Classes from Derived Classes. Learn How to Call Base Class Members. Learn How to Hide Base Class Members. Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse existing code. Through effective employment of reuse, you can save time in your programming. Execute the following code to understand the flow of information 1. Create an empty project. 2. Add class to the project and name it Parent.cs 3. Add public with the class and then type the following code in parent class
4.
public Parent() { Console.WriteLine("Parent Constructor."); } public void print() { Console.WriteLine("I'm a Parent Class."); }

5. Add another class to the project and name it Child.cs 6. For inheritance public class Child : Parent 7. Add public with the class and type the following code in child class.
8.
public Child() { Console.WriteLine("Child Constructor."); }

9. Add class for main and name it demo.cs 10. Create the object for child class as follows
public static void Main() { Child child = new Child(); child.print(); Console.ReadLine(); }

Now go to Build tab and build the solution and if there is no compilation errors then execute the code and observe the order of function calls. //

using System; using System.Collections.Generic; //using System.Linq;

DCE Prepared by Natalia Ahmed


using System.Text; namespace check { class student { string name; string degree; double cgpa; string regnum;

IBIT

Lab4

public void setname() { Console.WriteLine("enter ur name "); name= Console.ReadLine(); } public void setregname() { Console.WriteLine ("enter ur regnum"); regnum= Console.ReadLine(); } public void setdegree() { Console.WriteLine("enter ur degree"); degree = Console.ReadLine(); } public void setcgpa() { Console.WriteLine("enter ur cgpa "); cgpa= Convert.ToDouble(Console.ReadLine());

} } }

using System; using System.Collections.Generic; //using System.Linq; using System.Text; namespace check

DCE Prepared by Natalia Ahmed


{ class studentmain {

IBIT

Lab4

static void Getname() { student obj = new student();// student ke name se jo ha us ka obj banate hain . obj.setname(); obj.setregname(); obj.setcgpa(); obj.setdegree();

class bani

} } }

You might also like