ASP Project Work
ASP Project Work
ASP Project Work
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace labassign1 { class HelloWorld { static void Main(string[] args) { Console.WriteLine("Hello world! My first program!"); Console.WriteLine("Type in a line and hit enter..."); Console.ReadLine(); } } }
Output:
Output:
} }
Output:
Console.WriteLine("x: "+x); x -= 5; Console.WriteLine("x: "+x); y += 3; Console.WriteLine("y: "+y); y /= 4; Console.WriteLine("y: "+y); y %= 7; Console.WriteLine("y: "+y); if (++a == b) { Console.WriteLine("a: "+a); Console.WriteLine("b: "+b); } if (a++ == b) { Console.WriteLine("i entered here!"); } Console.WriteLine("a: "+a); Console.WriteLine("b: "+b); n = m >> 2; Console.WriteLine("n: "+n); m <<= 8; Console.WriteLine("m: "+m);
Submitted By: Samit Tandukar |Dot Net Training Basic 8
Console.ReadLine(); } } }
Output:
LAB ASSIGNMENT 5: Write a program that reads exactly one command line
argument, the name of a country. Depending upon the name of the country, the program will output the primary language spoken in that country. If the user has not supplied any command line arguments, then the program must display a message that says something like You did not supply the country name (feel free to change this as you wish) and exit. If the user has supplied more than one command line argument, then the program must display a message that says something like You must provide only one command line argument (feel free to change this as you wish) and exit. If the user has supplied exactly one command line argument, then the program must use a switch statement to output the language for that country. For example, the input can be usa, uk, aus, india, nepal, china, italy, canada, etc. Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace labassign_5 { class Program { static void Main(string[] args) { if (args.Length == 1) { for (int i = 0; i < args.Length; i++) {
10
Console.WriteLine(args[i]); switch (args[i]) { case "Nepal": Console.WriteLine("language is nepali"); break; case "UK": Console.WriteLine("language is Uk english"); break; case "USA": Console.WriteLine("language is US English"); break; case "Japan": Console.WriteLine("language is japanese"); break; default: Console.WriteLine("country is not in the list"); break; } } } else { Console.WriteLine("you must provide only one country name");
Submitted By: Samit Tandukar |Dot Net Training Basic 11
} Console.ReadLine(); } } }
Output:
12
13
14
15
LAB ASSIGNMENT 6: Write a program that will ask the user to enter one integer;
then again ask to enter another integer. Then the program will ask the user to enter one of plus ('+'), minus ('-'), multiply ('*'), divide ('/'). After this, the program will perform the user requested operation between the two integers and print the result in the console. Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace labassign6 { class Program { static void Main(string[] args) { int num1, num2, result; Console.WriteLine("enter 1st integer"); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter 2nd integer"); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("choose operation '+','-','*' or '/': "); char oper = Convert.ToChar(Console.ReadLine()); switch (oper)
Submitted By: Samit Tandukar |Dot Net Training Basic 16
{ case '+': result = num1 + num2; Console.WriteLine("sum of {0} and {1} is {2}", num1, num2, result); break; case '-': result = num1 - num2; Console.WriteLine("difference of {0} and {1} is {2}", num1, num2, result); break; case '*': result = num1 * num2; Console.WriteLine("product of {0} and {1} is {2}", num1, num2, result); break; case '/': result = num1 / num2; Console.WriteLine("division of {0} and {1} is {2}", num1, num2, result); break; default: Console.WriteLine("please choose appropriate operator"); break; } Console.ReadLine(); } }
Submitted By: Samit Tandukar |Dot Net Training Basic 17
Output:
18
19
LAB ASSIGNMENT 7: Print 1 to 100 in the following format by displaying only ten
digits in a single line. You can either put space or tab between numbers in a single row. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 . . . 61 . . . 70 71 . . . 80 81 . . . 90 91 92 93 94 95 96 97 98 99 100 Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace labassign7 { class Program { static void Main(string[] args)
Submitted By: Samit Tandukar |Dot Net Training Basic 20
...
60
Output:
21
LAB ASSIGNMENT 8: Explore static vs. non-static classes and its usages. Report
any issues you find. Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace labassign8 { public static class Conversions { public static double feetToMeter(double f) { return (f * 0.305); } public static double meterToFeet(double m) { return (m * 3.281); } } public class Car { public static uint Wheels = 4;
Submitted By: Samit Tandukar |Dot Net Training Basic 22
public int mileage; public static uint getManufacturerId() { return 532; } public int getMileage() { return this.mileage; } } public class MyExample { public static void Main() { double x = Conversions.feetToMeter(35.00); double y = Conversions.meterToFeet(40.00); Car C = new Car(); C.mileage = 19; Console.WriteLine(Car.Wheels); Console.WriteLine(C.mileage); Console.WriteLine(Car.getManufacturerId()); Console.WriteLine(C.getMileage()); } }
Submitted By: Samit Tandukar |Dot Net Training Basic 23
Output:
24
LAB ASSIGNMENT 9: Write a program that inputs 3 integers from the keyboard
and prints the sum, average, product, smallest and largest of these numbers. The screen output must be like the following: Input three different integers: 5, 5, 8 Sum is 18 Average is 6 Product is 200 Smallest is 5 Largest is 8 Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace labassign9 { class Program { static void Main(string[] args) { int num1, num2, num3, sum, product, average, small, large; Console.Write("Input three different integers: "); num1= Convert.ToInt32(Console.ReadLine());
Submitted By: Samit Tandukar |Dot Net Training Basic 25
num2 = Convert.ToInt32(Console.ReadLine()); num3 = Convert.ToInt32(Console.ReadLine()); sum = num1 + num2 + num3; average = sum / 3; product = num1 * num2 * num3; small = num1; large = num1; if (num2 < small) { small = num2; } if (num3 < small) { small = num3; } if (num2 >large) { large = num2; } if (num3 > large) { large = num3; } Console.WriteLine("sum is {0}",sum);
Submitted By: Samit Tandukar |Dot Net Training Basic 26
Console.WriteLine("average is {0}",average); Console.WriteLine("product is {0}",product); Console.WriteLine("smallest number is {0}", small); Console.WriteLine("largest number is {0}",large); Console.ReadLine(); } } }
Output:
27
LAB ASSIGNMENT 10: Write a program that calculates the squares, cubes and
square roots of numbers from 0 to 100 and prints it to the console in the following manner: Integer square cube square root 0 1 2 3 4 ... 100 10000 1000000 10 Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace labassign10 { class Program { static void Main(string[] args) { Console.WriteLine("{0,-8} {1,-8} {2,-8} {3}", "Integer", "Square", "Cube", "Square Root");
Submitted By: Samit Tandukar |Dot Net Training Basic 28
0 1 4 9 16
0 1 8 27 64
0 1 1.41 1.73 2
for (int n = 0; n <= 100; n++) { int num = n; int sq = num * num; int cube = sq * num; double root = Math.Sqrt(num); double sqrt = Math.Round(root, 3); Console.WriteLine("{0,-8} {1,-8} {2,-8} {3}", num, sq, cube, sqrt); } Console.ReadLine(); } } }
Output:
29