You are on page 1of 4

LAB 03

NAME: M.Anwar Raza


ROLL NO: 2020-BSCS-015
SEC: A
TASK 01
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleLab03
{
public class Book
{
public string Title;
public string Author;
public short YearPublished;
public int NumberOfPages;
public char CoverType;
}

public class Exercise


{

static void Main()


{
Book First = new Book();

First.Title = " Turbo C ";


First.Author = "Robert Lafore";
First.YearPublished = 1996;
First.NumberOfPages = 872;
First.CoverType = 'H';
Console.WriteLine("Book Characteristics");

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:

TASK 02
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleLab03
{
public class Student
{
public string name = "M.Anwar Raza";
public int age = 19;
public int englishMarks = 88;
public int mathsMarks = 94;
public int scienceMarks = 85;
public int totalMarks = 300;
public int obtainedMarks;
public int percentage;

public int CalculateTotalMarks()


{
obtainedMarks = englishMarks + mathsMarks + scienceMarks;
return obtainedMarks;
}
public int CalculatePercentage()
{
percentage = (obtainedMarks * 100)/ totalMarks ;
return percentage;
}
}
class Program
{
static void Main(string[] args)
{
Student s1 = new Student();
Console.WriteLine("Student's Name: {0}", s1.name);
Console.WriteLine("Student's Age: {0}", s1.age);
Console.WriteLine("Total Marks Obtained by {0} are {1}", s1.name,
s1.CalculateTotalMarks());
Console.WriteLine("{0} got {1}% ",s1.name ,s1.CalculatePercentage());
Console.ReadLine();
}
}
}

OUTPUT:

TASK 03
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleLab03
{
class Program
{
string inputUser()
{
string name;
Console.WriteLine("Enter Your Name: ");
name = Console.ReadLine();
return name;
}
int numberOfVowels(string x)
{
int vowels = 0;

for (int i = 0; i < x.Length; i++)


{
if (x[i] == 'a' || x[i] == 'e' || x[i] == 'i' || x[i] == 'o' || x[i]
== 'u' ||
x[i] == 'A' || x[i] == 'E' || x[i] == 'I' || x[i] == 'O' || x[i]
== 'U')
{
vowels++;
}
}
return vowels;
}
static void Main(string[] args)
{
Program n1 = new Program();
Console.WriteLine("The No. of Vowels are: {0}",
n1.numberOfVowels(n1.inputUser()));
Console.ReadKey();
}
}
}

OUTPUT:

You might also like