Nothing Special   »   [go: up one dir, main page]

Task No 1:: (Lab No.03) (Computer Programming) (Primitive Types and Variables)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

[Lab no.

03] [Computer Programming]


[Primitive types and Variables]
TASK NO 1: Which of the following values can be assigned to variables of type float, double
And Decimal: 5, -5.01, 34.567839023; 12.345; 8923.1234857; 3456.09112487595654215125668?

CODE:
{
static void Main(string[] args)
{
int a = 5;
Console.WriteLine("Value {0} assigned to int variable", a);
float b = -5.01f, c = 12.345f;
Console.WriteLine("Value {0} and {1} assigned to float variable", b, c);
double d = 34.567839023, e = 8923.1234857, f = 3456.09112486578976554;
Console.WriteLine("Value {0} , {1} , {2} assigned to double variable", d, e, f);

}
}
}

OUTPUT:
[Lab no.03] [Computer Programming]
[Primitive types and Variables]
TASK NO 2: Declare two variables of type string and give them values “Hello” and “world”.
Assign the value obtained by the concatenation of the two variables of type string (do not miss the
space in the middle) to a variable of type object.

CODE:

{
static void Main(string[] args)
{
String a1 = "Hello", a2 = "World";
Console.WriteLine(" Concatination of 2 strings: " + a1 + " " + a2);

}
}
}

OUTPUT:
[Lab no.03] [Computer Programming]
[Primitive types and Variables]

TASK NO 3: A company dealing with marketing wants to keep a data record of its
employees. Each record should have the following characteristic – first name, last name, age, gender
(‘m’or ‘f’) and unique employee number (27560000 to 27569999). Declare appropriate variable
needed to maintain the information for an employee by using the appropriate data types and attribute
names.

CODE:
{
static void Main(string[] args)
{
Console.WriteLine(" ---------------------- MH Corporation ----------------------");
Console.WriteLine("---------------------- Employee Record ----------------------");
Console.WriteLine("Please enter your employee id?");
String id = Console.ReadLine();
Console.WriteLine("Please enter your first name?");
String firstname = Console.ReadLine();
Console.WriteLine("Please enter your last name?");
String lastname = Console.ReadLine();
Console.WriteLine("Please enter your age?");
String age = Console.ReadLine();
Console.WriteLine("Please enter your gender ( m or f) ?");
char gender = Convert.ToChar(Console.ReadLine());
Console.Clear();
Console.WriteLine(" ---------------------- MH Corporation ----------------------");
Console.WriteLine("---------------------- Employee Record ----------------------");
Console.WriteLine(" Employee id: " + id);
Console.WriteLine(" first Name: " + firstname + " Last Name: " + lastname);
Console.WriteLine(" Age : " + age);
Console.WriteLine(" gender: " + gender);

}
}
}

OUTPUT:
[Lab no.03] [Computer Programming]
[Primitive types and Variables]

TASK NO 4: A given company has name, address, phone number, fax number, web site and
manager. The manager has name, surname and phone number. Write a program that reads
information about the company and its manager and then prints it on the console.

CODE:
{
Console.WriteLine("---------------------- Compnay Timeline Generator
----------------------");
Console.WriteLine("Please enter Company Name:");
String companyname = Console.ReadLine();
Console.WriteLine("Please enter Company Address:");
String add = Console.ReadLine();
Console.WriteLine("Please enter company phone number");
String phone = Console.ReadLine();
Console.WriteLine("Please enter fax number?");
String fax = Console.ReadLine();
Console.WriteLine("Please enter Company Website?");
String web = Console.ReadLine();
Console.WriteLine("Please enter Manager Name?");
String manager = Console.ReadLine();
Console.WriteLine("Please enter Manager Sur number?");
String mansur = Console.ReadLine();
Console.WriteLine("Please enter mnager phone number?");
String manphone = Console.ReadLine();
Console.Clear();
Console.WriteLine(" ---------------------- {0} ----------------------", companyname);
Console.WriteLine("----------------Welcome To Company Timeline ----------------");
Console.WriteLine(" Comapnay Name: " + companyname);
Console.WriteLine(" Comapny Address: " + add);
Console.WriteLine(" Phone Number : " + phone + " Fax: " + fax);
Console.WriteLine(" Company Web : " + web);
Console.WriteLine(" ---------------------- Manager Info ----------------------");
Console.WriteLine(" Manager Name: " + manager);
Console.WriteLine(" Manager Sur Name:" + mansur);
Console.WriteLine(" Manager Phone #: " + manphone);

}
}
}

OUTPUT:
[Lab no.03] [Computer Programming]
[Primitive types and Variables]

You might also like