Upload
samit-tandukar
View
217
Download
0
Embed Size (px)
Citation preview
8/13/2019 ASP Project Work
1/29
Submitted By: Samit Tandukar |Dot Net Training Basic 1
LAB ASSIGNMENT 1:Very First Program. Write, compile and run.
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();
}
}
}
8/13/2019 ASP Project Work
2/29
Submitted By: Samit Tandukar |Dot Net Training Basic 2
Output:
8/13/2019 ASP Project Work
3/29
Submitted By: Samit Tandukar |Dot Net Training Basic 3
LAB ASSIGNMENT 2: Learning to use command line arguments. Write, compile
and run.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace labassign2
{
class ReadingCommandLine
{
static void Main(string[] args)
{
for (int x = 0; x < args.Length; x++)
{
Console.WriteLine(args[x]);
}
Console.ReadLine();
}
}
}
8/13/2019 ASP Project Work
4/29
Submitted By: Samit Tandukar |Dot Net Training Basic 4
Output:
8/13/2019 ASP Project Work
5/29
Submitted By: Samit Tandukar |Dot Net Training Basic 5
LAB ASSIGNMENT 3: The purpose of this assignment is to understand that strings
are immutable. Write, compile and run.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace labassign3
{
class LearningStrings
{
static void Main(string[] args)
{
string intro = "Hello, I am learning ";
string study = "DOT NET Basic at DWIT.";
string s1 = intro + study;
Console.WriteLine(s1);
string s2 = intro;
intro = "Hi there! I plan to join";
Console.WriteLine(intro);
Console.WriteLine(s2);
Console.ReadLine();
}
8/13/2019 ASP Project Work
6/29
Submitted By: Samit Tandukar |Dot Net Training Basic 6
}
}
Output:
8/13/2019 ASP Project Work
7/29
Submitted By: Samit Tandukar |Dot Net Training Basic 7
LAB ASSIGNMENT 4: Use of operators. Write code as instructed by the commentstarting with To Do. Only the Main () method is shown here, you have to complete
the rest.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace labassign4
{
class Operators
{
static void Main(string[] args)
{
int x = 7, y = 9, z = 0;
uint a = 5, b = 6;
uint m = 0xFADE, n = 0;
z = x & y;
Console.WriteLine("z: "+z);
z = x | y;
Console.WriteLine("z: "+z);
z = x ^ y;
Console.WriteLine("z: "+z);
x *= 2;
8/13/2019 ASP Project Work
8/29
Submitted By: Samit Tandukar |Dot Net Training Basic 8
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/13/2019 ASP Project Work
9/29
Submitted By: Samit Tandukar |Dot Net Training Basic 9
Console.ReadLine();
}
}
}
Output:
8/13/2019 ASP Project Work
10/29
Submitted By: Samit Tandukar |Dot Net Training Basic 10
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 messagethat 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++)
{
8/13/2019 ASP Project Work
11/29
Submitted By: Samit Tandukar |Dot Net Training Basic 11
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");
8/13/2019 ASP Project Work
12/29
Submitted By: Samit Tandukar |Dot Net Training Basic 12
}
Console.ReadLine();
}
}
}
Output:
8/13/2019 ASP Project Work
13/29
Submitted By: Samit Tandukar |Dot Net Training Basic 13
8/13/2019 ASP Project Work
14/29
Submitted By: Samit Tandukar |Dot Net Training Basic 14
8/13/2019 ASP Project Work
15/29
Submitted By: Samit Tandukar |Dot Net Training Basic 15
8/13/2019 ASP Project Work
16/29
Submitted By: Samit Tandukar |Dot Net Training Basic 16
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 resultin 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)
8/13/2019 ASP Project Work
17/29
Submitted By: Samit Tandukar |Dot Net Training Basic 17
{
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();
}
}
8/13/2019 ASP Project Work
18/29
Submitted By: Samit Tandukar |Dot Net Training Basic 18
}
Output:
8/13/2019 ASP Project Work
19/29
Submitted By: Samit Tandukar |Dot Net Training Basic 19
8/13/2019 ASP Project Work
20/29
Submitted By: Samit Tandukar |Dot Net Training Basic 20
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 . . . . . . 60
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)
8/13/2019 ASP Project Work
21/29
Submitted By: Samit Tandukar |Dot Net Training Basic 21
{
for (int n = 1; n
8/13/2019 ASP Project Work
22/29
Submitted By: Samit Tandukar |Dot Net Training Basic 22
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;
8/13/2019 ASP Project Work
23/29
Submitted By: Samit Tandukar |Dot Net Training Basic 23
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());
}
}
8/13/2019 ASP Project Work
24/29
Submitted By: Samit Tandukar |Dot Net Training Basic 24
}
Output:
8/13/2019 ASP Project Work
25/29
Submitted By: Samit Tandukar |Dot Net Training Basic 25
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());
8/13/2019 ASP Project Work
26/29
Submitted By: Samit Tandukar |Dot Net Training Basic 26
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);
8/13/2019 ASP Project Work
27/29
Submitted By: Samit Tandukar |Dot Net Training Basic 27
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:
8/13/2019 ASP Project Work
28/29
8/13/2019 ASP Project Work
29/29
for (int n = 0; n