You are on page 1of 9

Name : Abdullah Rafiq

Registration # : 19-NTU-CS-1037
Assignment # : LAB-7
Course Code : CSC2071
Course Name : OOP
Semester : 3RD
Section : BSCS-III
Department : Department of Computer Science
Date : Thursday, January 14, 2021

1|Page
BSCS-III, DCS, NTU FSD
QUESTION 1:
SOLUTION CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Question_No._1
{
class Program
{
static void Main(string[] args)
{
Trip trip1 = new Trip();
int choice=0;
int choice1 = 0;
Console.WriteLine("\tWelcome to Trip System");
Console.WriteLine("\nEnter the Data of Trip");
Console.Write("\nEnter the Destination : ");
trip1.destination = Console.ReadLine();
Console.Write("\nEnter the Distance Traveled : ");
trip1.distanceTraveled = double.Parse(Console.ReadLine());
while (choice1 != 4)
{
Console.WriteLine("\nPress 1 to Calculate the Cost Per Mile");
Console.WriteLine("\nPress 2 to Calculate the No of Miles Per Galon");
Console.WriteLine("\nPress 3 For Complete Display Method");
Console.WriteLine("\nPress 4 to Exit");
choice = int.Parse(Console.ReadLine());

if (choice == 1)
{
Console.Write("Cost Per Mile : ");
Console.WriteLine(trip1.CalculationOfCostPerMile());
}
else if (choice == 2)
{
Console.Write("Miles Per Gallon : ");
Console.WriteLine(trip1.CalculationOfMilePerGallon());
}
else if (choice == 3)
{
trip1.Disp();
}
choice1=choice;
}
}
}
}

Trip Class:

2|Page
BSCS-III, DCS, NTU FSD
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Question_No._1
{
class Trip
{
private string Destination;
private double DistanceTraveled;
private double TotalCostOfGasoline;
private int NoOfGallonsConsumed;
public Trip()
{
this.Destination = "Alabad";
this.DistanceTraveled = 21.5;
this.TotalCostOfGasoline = 2549;
this.NoOfGallonsConsumed = 5;
}
public string destination
{
get { return this.Destination; }
set { this.Destination = value; }
}
public double distanceTraveled
{
get { return this.DistanceTraveled; }
set { this.DistanceTraveled = value; }
}
public double totalCostOfGasoline
{
get { return this.TotalCostOfGasoline; }
set { this.TotalCostOfGasoline = value; }
}
public int noOfGallonsConsumed
{
get { return this.NoOfGallonsConsumed; }
set { this.NoOfGallonsConsumed = value; }
}
public double CalculationOfMilePerGallon()
{
return this.DistanceTraveled / this.NoOfGallonsConsumed;
}
public double CalculationOfCostPerMile()
{
return this.DistanceTraveled / this.TotalCostOfGasoline;
}
public void Disp()
{
Console.WriteLine("Destination : "+this.Destination);
Console.WriteLine("DistanceTraveled : "+this.DistanceTraveled);
Console.WriteLine("TotalCostOfGasoline : "+this.TotalCostOfGasoline);
Console.WriteLine("NoOfGallonsConsumed : "+this.NoOfGallonsConsumed);
Console.WriteLine("Calculation Of Miles Per Gallon : " +
CalculationOfMilePerGallon());
Console.WriteLine("Calculation Of Cost Per Mile : " + CalculationOfCostPerMile());

3|Page
BSCS-III, DCS, NTU FSD
}
}
}

OUTPUT SECREENSHOT:

QUESTION 2:
SOLUTION CODE:
using System;

public class Program


{
public static void Main(string[] args)
{
Fraction fraction1 = new Fraction(2, 4);
Console.Write("Enter the Dividend : ");
fraction1.dividend1 = double.Parse(Console.ReadLine());
Console.Write("Enter the Divisor : ");
fraction1.divisor1 = double.Parse(Console.ReadLine());
Console.Write("Press 'd' OR 'D' for display : ");
char choice = char.Parse(Console.ReadLine());
if (choice == 'd' || choice == 'D')
{
fraction1.disp();
}
else
Console.WriteLine("Invalid Input!");
Console.ReadLine();
}

4|Page
BSCS-III, DCS, NTU FSD
class Fraction
{
private double Dividend;
private double Divisor;
public Fraction(double dividend, double divisor)
{
this.Dividend = dividend;
this.Divisor = divisor;
}
public double dividend1
{
get { return this.Dividend; }
set { this.Dividend = value; }
}
public double divisor1
{
get { return this.Divisor; }
set { this.Divisor = value; }
}
public void disp()
{
Console.WriteLine("Fraction = " + this.Dividend + "/" + this.Divisor);
}
}

OUTPUT SECREENSHOT:

QUESTION 3:
SOLUTION CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Question_No._3
{
class Program

5|Page
BSCS-III, DCS, NTU FSD
{
static void Main(string[] args)
{
int choice1=0;
int choice2 = 0;
MealCard mealcard1 = new MealCard();
while (choice2 != 6)
{
Console.WriteLine("\tWelcome to MealCard System");
Console.WriteLine("Press 1 to Enter the Data of Student");
Console.WriteLine("Press 2 to Enter the Purchase Food");
Console.WriteLine("Press 3 for Price List");
Console.WriteLine("Press 4 to Add Balance");
Console.WriteLine("Press 5 to Check Balance");
Console.WriteLine("Press 6 to Exit");
choice1 = int.Parse(Console.ReadLine());
if (choice1 == 1)
{
Console.Write("Enter the Name of Student : ");
mealcard1.studentName=Console.ReadLine();
Console.Write("Enter the Student ID : ");
mealcard1.studentID = int.Parse(Console.ReadLine());
Console.WriteLine("Congaratulations! You have Got 100 Points as Blanace For
Creating Account");
}
else if (choice1 == 2)
{
int choice3 = 0;
while (choice3 != 3)
{
Console.WriteLine("Press 1 to Purchase Biryani");
Console.WriteLine("Press 2 to Purchase Drink");
Console.WriteLine("Press 3 to Exit");
int choice = int.Parse(Console.ReadLine());
if (choice == 1)
{
mealcard1.DeductionForBiryani();
}
else if (choice == 2)
{
mealcard1.DeductionForDrink();
}
choice3 = choice;
}
}
else if (choice1 == 3)
{
Console.Write("\nPrice of Biryani is " + mealcard1.priceOfBiryani);
Console.Write("\nPrice of Drink is " + mealcard1.priceOfDrink);
Console.Write("\n");
}
else if (choice1 == 4)
{
Console.Write("Enter the ammount of Points you wanna add to balance : ");
mealcard1.AddBalance(int.Parse(Console.ReadLine()));
Console.WriteLine();
}
else if (choice1 == 5)

6|Page
BSCS-III, DCS, NTU FSD
{
Console.Write("Your Current Balance is : " + mealcard1.balance);
Console.WriteLine();
}
choice2 = choice1;
}
}
}
}

MealCard Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Question_No._3
{
class MealCard
{
private string StudentName;
private int StudentID;
private int Balance=100;//Currency of balance is points
private int PriceOfBiryani = 70;
private int PriceOfDrink = 30;
public string studentName
{
get { return this.StudentName; }
set { this.StudentName = value; }
}
public int studentID
{
get { return this.StudentID; }
set { this.StudentID = value; }
}
public int priceOfBiryani
{
get { return this.PriceOfBiryani; }
set { this.PriceOfBiryani = value; }
}
public int priceOfDrink
{
get { return this.PriceOfDrink; }
set { this.PriceOfDrink = value; }
}
public int balance
{
get { return this.Balance; }
set { this.Balance = value; }
}
public void AddBalance(int points)
{
this.Balance = this.Balance + points;
}
public void DeductionForBiryani()
{

7|Page
BSCS-III, DCS, NTU FSD
if (this.Balance >= this.PriceOfBiryani)
{
this.Balance = this.Balance - this.PriceOfBiryani;
Console.WriteLine("You have successfully Purchased Biryani");
}
else
Console.WriteLine("Your balance is unsufficient!!");
}
public void DeductionForDrink()
{
if (this.Balance >= this.PriceOfDrink)
{
this.Balance = this.Balance - this.PriceOfDrink;
Console.WriteLine("You have successfully Purchased Drink");
}
else
Console.WriteLine("Your balance is unsufficient!!");
}
}
}

OUTPUT SECREENSHOT:

8|Page
BSCS-III, DCS, NTU FSD
9|Page
BSCS-III, DCS, NTU FSD

You might also like