You are on page 1of 10

BAHRIA UNIVERSITY, ISLAMABAD

Department of Computer Science

Visual Programming
Lab Journal 3
Student Name: SALMAN AYUB KHAN

Enrolment No.: 01-235181-051


============================================================

Title: Getting Started with C#.NET


Objectives: To understand about the fundamentals of c#.NET.
Tools Used: visual studio 2019

Procedure: Open VS and perform the following tasks

Exercise 1

Create a Console application for tax calculation. Accept money as input from the user and calculate
the tax using the following table. Display the output to the user.

Money Percentage Total Tax


Less than 10,000 5% ?
10,000 to 100,000 8% ?
More than 100,000 8.5% ?

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tax_calculation
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Tax Calculator " +"\n");

Visual Programming Lab Journal 01-235181-051


Console.WriteLine("******************************");
Console.Write("Enter the money :");
double money = double.Parse(Console.ReadLine());
double tax;

if (money < 10000)


{
tax = .05 * money;
}

else if (money <= 100000)


{
tax = .08 * money;
}

else
{
tax = .085 * money;
}

Console.WriteLine("Your Tax is : " + tax);


Console.ReadLine();

}
}
}

OUTPUT:

Exercise 2

Create a console application named Calculator. Display the respective menu to the user and input
two numbers from the user, on which the respective operations could be performed.

Menu
Press 1 for add
Press 2 for subtraction
Press 3 for multiplication
Press 4 for Division
Press 5: for exit

Visual Programming Lab Journal 01-235181-051


CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" Press 1 for Addition\n Press 2 for Subtraction\n Press 3 For
Multiplication\n Press 4 for Division\n Press 5 for Exit :\n");
Console.Write("Enter Your Choice :");
int choice=Convert.ToInt32(Console.ReadLine());
Console.Write("Enter first number :");

int num1 = Convert.ToInt32(Console.ReadLine());


Console.Write("Enter second number:");
int num2 = Convert.ToInt32(Console.ReadLine());
int result = 0;

switch (choice)
{
case 1:
result = num1 + num2;
break;

case 2:
result = num1 - num2;
break;

case 3:
result = num1 * num2;
break;

case 4:
result = num1 / num2;
break;

case 5:

break;
default:
break;
}
Console.WriteLine("\nThe Result is : " + result);
Console.ReadLine();
}
}
}

Visual Programming Lab Journal 01-235181-051


OUTPUT:

Visual Programming Lab Journal 01-235181-051


Visual Programming Lab Journal 01-235181-051
Exercise 3
Create a console application which, print the the character “x” in the following pattern.

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{

Console.Write("Enter the number of Rows :");

int n = Convert.ToInt32(Console.ReadLine());
Console.Write("\n");
for (int i = n; i >= 1; i--)
{

for (int s = i; s < n; s++)

Console.Write(" ");

for (int j = 1; j <= (2 * i - 1); j++)

Console.Write("x");
Console.Write("\n");

}
Console.ReadLine();
}

}
}

Visual Programming Lab Journal 01-235181-051


OUTPUT:

Exercise 4
Create a windows form application and repeat the same task above for it. This time the pattern
should appear on a message box.

CODE:

public partial class Form1 : Form


{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int n = 15;
string star = "";
string title="Stars";

for (int i = n; i >= 1; i--)


{

for (int s = i; s < n; s++)

Visual Programming Lab Journal 01-235181-051


star += " ";

for (int j = 1; j <= (2 * i - 1); j++)

star+="x";
star+="\n";

MessageBox.Show(star,title,MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Information);
}
}
}

OUTPUT:

Visual Programming Lab Journal 01-235181-051


Exercise 5
Create a console application which prints numbers from (1-15) in the following pattern using For
Loop.

CODE:

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

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{

Console.Write("Enter the rows :");


int num = Convert.ToInt32(Console.ReadLine());
Console.Write("\n");
int x = 1;

for (int i = 1; i <= num; i++)

Visual Programming Lab Journal 01-235181-051


{
for (int j = 1; j <= i; j++) // j i times chalyga or x ki value har time
increment hoge.
{
Console.Write(x+" ");
x++;
}
Console.Write("\n"); // j ka loop katam hony ka bad agli line sa start hoga

}
Console.ReadLine();

}
}

OUTPUT:

Submission Date: Signature Ms. Umarah Qaseem

Visual Programming Lab Journal 01-235181-051

You might also like