PRACTICAL 1 a] Create an application that obtains four int values from the user
and displays the product.
Methods :
1. Console.WriteLine() : This method is used to print data along with printing the
new line.
2. Console.ReadLine() : This method is used to read the next line of
characters from the standard input stream.
3. Convert.ToInt32() : Converts the specified string representation of a number
to an equivalent 32-bit signed integer.
4. Console.ReadKey() : Obtains the next character or function key pressed by
the user. The pressed key is displayed in the console window.
Code :
using System;
namespace practical_no1a
{
class Program
{
static void Main(string[] args)
{
int num1, num2, num3, num4, prod;
Console.WriteLine("enter value for num1 :");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter value for num2 :");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter value for num3 :");
num3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter value for num4:");
num4 = Convert.ToInt32(Console.ReadLine());
prod = num1* num2 * num3 * num4;
Console.WriteLine("product of " + num1 + "*" + num2 + "*" + num3 + "*" + num4 + "=" +
prod);
Console.ReadKey();
}
}
}
Output:
PRACTICAL 1 b] Create an application to demonstrate string operations.
Methods :
1. ToUpper() : Returns a copy of this string converted to uppercase.
2. Trim() : Removes all leading and trailing white-space characters from the
current string.
3. Insert() : Returns a new string in which a specified string is inserted at a
specified index position in this instance.
4. ToLower() : Returns a copy of this string converted to lowercase.
5. Concat() : Concatenates one or more instances of String, or
the String representations of the values of one or more instances of Object.
6. Copy() : Creates a new instance of String with the same value as a
specified String.
7. Console.Read() : Reads the next character from the standard input stream.
Code :
using System;
namespace practical_no1b
{
class Program
{
static void Main(string[] args)
{
String s1 = " good morning ", ans;
String s2 = "STUDENTS";
String s3 = " ";
ans = s1.ToUpper();
Console.WriteLine(ans);
ans = s1.Trim();
Console.WriteLine(ans);
ans = s1.Insert(2, "p");
Console.WriteLine(ans);
ans = s2.ToLower();
Console.WriteLine(ans);
ans = String.Concat(s1, s2);
Console.WriteLine(ans);
s3 = String.Copy(s1);
Console.WriteLine(s3);
Console.Read();
}
}
}
Output:
PRACTICAL 1 c] Create an application that receives the (Student Id, Student
Name, Course Name, Date of Birth) information from a set of students. The
application should also display the information of all the students once the data
entered.
Methods :
1. Console.Write() : Is used to print data without printing the new line.
2. int.Parse() : Convert a string representation of number to an integer.
3. DateTime.Parse() : Converts the string representation of a date and time to
its DateTime equivalent.
4. ToShortDateString() : This method is used to convert the value of the current
DateTime object to its equivalent short date string representation.
Code :
using System;
namespace practial1c
{
struct student
{
int sid;
String sname;
String cname;
DateTime dob;
public void Accept()
{
Console.Write("Student id: ");
sid = int.Parse(Console.ReadLine());
Console.Write("Student Name: ");
sname = Console.ReadLine();
Console.Write("Course Name: ");
cname = Console.ReadLine();
Console.Write("date of birth: ");
dob = DateTime.Parse(Console.ReadLine());
public void display()
{
Console.Write("student id {0}\n student name {1}\n course name {2}\n
date of birth {3}\n",sid,sname,cname,dob.ToShortDateString());
}
class Program
{
static void Main(string[] args)
{
student[] allstudents = new student[3];
for(int i = 0; i < allstudents.Length; i++)
allstudents[i].Accept();
Console.WriteLine("*****************");
Console.WriteLine("student information");
Console.WriteLine("*****************");
for(int i = 0; i < allstudents.Length; i++)
allstudents[i].display();
Console.ReadKey();
}
}
}
Output: