Lab 3
Lab 3
Overview of Classes
A Class Is an Active Data Structure
A class is a data structure that can store data and execute code. It contains the following:
• Data members, which store data associated with the class or an instance of the class. Data
Members generally model the attributes of the real-world object the class represents.
• Function members, which execute code. Function members generally model the functions and
actions of the real-world object the class represents.
A C# class can have any number of data and function members. The members can be any Combination
of nine possible member types. These member types are shown in Table 4-1.
Declaring a Class
The class declaration provides the following:
• The class name
• The members of the class
• The characteristics of the class
Task:
1. Write the output of the following program.
using System;
Console.Write("Title: ");
Console.WriteLine(First.Title);
Console.Write("Author: ");
Console.WriteLine(First.Author);
Console.Write("Year: ");
Console.WriteLine(First.YearPublished);
Console.Write("Pages: ");
Console.WriteLine(First.NumberOfPages);
Console.Write("Cover: ");
Console.WriteLine(First.CoverType);
Console.ReadKey();
}
}
Output:
----------------------------------------------------------------------------------------------------------------
2. Create a class student with a data members name, age, marks of English , marks of
math, marks of science, total marks, obtained marks and percentage provide
member functions CalculateTotalMarks and CalculatePercentage to calculate
marks and percentage in main.
Input:
Output:
-------------------------------------------------------------------------------------------------------
3. Write a program that contains a class which has a method that takes user name as
input and second functions which returns number of vowels present in it and Main
program prints the number of vowels.
Input:
Output:
--------------------------------------------------------------------------------------------------------
4. Write a program that performs typecasting of atleast 3 predefined datatypes in C#.
Input:
O
Output:
---------------------------------------------------------------------------------------------------------
5. Write a C# program that takes a number as input and displays it four times in a row
(separated by blank spaces), and then four times in the next row, with no
separation. You should do it twice: Use the console. Write and use {0}.
Test Data:
Enter a digit: 25
Expected Output:
25 25 25 25
25252525
25 25 25 25
25252525
Input:
Output: