0% found this document useful (0 votes)
26 views3 pages

Lab#9 Objective: Write A Program Which Takes An Input of Time1 and Time2 and Calculate There Diffrence Program

The document describes a C# program that takes time inputs in hours, minutes, and seconds for two times (time1 and time2), calculates the difference between the two times in hours, minutes, and seconds, and displays the results. The program uses classes to calculate the total seconds for each inputted time and then calculates the difference between the two totals.

Uploaded by

Ahsan Jamal
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)
26 views3 pages

Lab#9 Objective: Write A Program Which Takes An Input of Time1 and Time2 and Calculate There Diffrence Program

The document describes a C# program that takes time inputs in hours, minutes, and seconds for two times (time1 and time2), calculates the difference between the two times in hours, minutes, and seconds, and displays the results. The program uses classes to calculate the total seconds for each inputted time and then calculates the difference between the two totals.

Uploaded by

Ahsan Jamal
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/ 3

Lab#9 Objective: write a program which takes an input of time1 and time2 and calculate there diffrence Program:

using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication10 { class Program { static void Main(string[] args) { int a, b, c, d, e, f; double ab, ac, ad, ae, af, ag, ah, ai,aj,ak; Class1 o = new Class1(); Console.WriteLine("ENTER TIME\n\n"); Console.WriteLine("Enter hour:"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter minute:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second:"); c= Convert.ToInt32(Console.ReadLine()); ab = o.calculate1(a, b, c); class2 p = new class2();

Console.WriteLine("ENTER TIME 2\n\n"); Console.WriteLine("Enter hour:"); d = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter minute:"); e = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second:"); f = Convert.ToInt32(Console.ReadLine()); ac = p.calculate2(d, e, f);

ad = ac - ab; ae = ad / 3600; af = Convert.ToDouble(Math.Floor(ae)); ag = ae - af; ah = ag * 60; ai = Convert.ToDouble(Math.Floor(ah)); ag = ah - ai; aj = ag * 60; ak = Convert.ToDouble(Math.Floor(aj)); Console.WriteLine("\n\nDIFFRENCE\n\nhour:{0} minute:{1} second:{2}",af,ai,ak); Console.ReadLine(); }}}

Class:
using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication10 { public class Class1 { public int calculate1(int hour1,int minute1,int second1) { int total=(hour1*3600)+(minute1*60)+second1; return total; } } public class class2 { public int calculate2(int hour2, int minute2, int second2) { int total=(hour2*3600)+(minute2*60)+second2; return total; }}

Output:
ENTER ENTER 10 ENTER 10 ENTER 10 ENTER ENTER 11 ENTER 11 ENTER 11 TIME HOUR: MINUTE: SECOND: TIME2 HOUR: MINUTE: SECOND:

DIFFRENCE HOUR:1 MINUTE:1 SECOND:1

You might also like