Bahria University,
Karachi Campus
COURSE: CSC-113 COMPUTER PROGRAMMING
TERM: FALL 2019, CLASS: BSE- 1 (A)
Submitted By:
____Zain Rizvi________________________46064_______
(Name) (Reg. No.)
Submitted To:
Engr. Adnan ur rehman/ Engr. Ramsha Mashood
Signed Remarks: Score:
INDEX
SNO DATE LAB LAB OBJECTIVE SIGN
NO
1 3/oct/2020 1 Programming Basic
2 11/oct/2020 2 Variable and Arithmetic operation
3 18/oct/2020 3 input and output
4 27/oct/2020 4 Formatted output
5 28/Nov/2020 5 operations and Expressions
6 29/Nov/2020 6 conditional statement
7 8/Nov/2020 7 LOOP
8 13/Nov/2020 8 while and do-while Loops
9 04/12/2020 9 Arrays
10 12/12/2020 10 2D Array
11 27/12/2020 11 Methods
SNO DATE LAB LAB OBJECTIVE SIGN
NO
Bahria University,
Karachi Campus
LAB EXPERIMENT NO.
____11___
LIST OF TASKS
TASK NO OBJECTIVE
1 Write a method named square_cube() that computes the square and cube of the value passed to
it and display the result. Ask the user to provide the integer input in the main() and then call the
function.
2 Write a method table() which generates multiplicative table of an integer. The function receives
three integers as its arguments. The first argument determine the table to be generated while
the second and the third integer tell the starting and ending point respectively. Ask the user to
provide the three integer as input in the main().
3 Create two function to find min and maximum value of any int array
4 Take input of an array in on method and print reverse of that array.
5 Design a fully functional calculator using function.
6 Design a WFP of your marks sheet
Submitted On:
27/ Dec /2020
(Date: DDMM/YY)
[Lab no.11] [Computer Programming]
[Methods]
Task No. 1: Write a method named square_cube() that computes the square and cube of
the value passed to it and display the result. Ask the user to provide the integer input in
the main() and then call the function.
Solution:
public void t1() {
Console.Write("Enter Number:");
int num = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Square :" + square(num));
Console.WriteLine("Cube :" + cube(num));
Console.ReadKey();
}
private static int cube(int num)
{
return num * num * num;
}
private static int square(int x)
{
// throw new NotImplementedException();
return x * x;
}
}
}
Output:
[Lab no.11] [Computer Programming]
[Methods]
Task No. 2: Write a method table() which generates multiplicative table of an integer. The
function receives three integers as its arguments. The first argument determine the table
to be generated while the second and the third integer tell the starting and ending point
respectively. Ask the user to provide the three integer as input in the main().
Solution:
class task2
{
public void t2() {
Console.WriteLine("Enter Number:");
int num= Convert.ToInt16( Console.ReadLine());
Console.WriteLine("Enter initial Number:");
int start = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter final Number:");
int end = Convert.ToInt16(Console.ReadLine());
while (end < start)
{
Console.WriteLine("final must be grater than the initial value");
Console.WriteLine("Enter final Number:");
end = Convert.ToInt16(Console.ReadLine());
}
Console.WriteLine("###########PRINT TABLE###########");
table(num,start,end);
}
private void table(int num, int start, int end)
{
//throw new NotImplementedException();
for (int i = start; i <= end; i++)
{
Console.WriteLine(" "+num + " x " + i + " = " + (i * num));
}
}
}
}
Output:
[Lab no.11] [Computer Programming]
[Methods]
Task No. 3: Create two function to find min and maximum value of any int array.
Solution:
public void t3() {
int[] num = new int[10];
for (int i = 0; i < num.Length; i++)
{
Console.Write("num["+i+"] + =");
num[i] =Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Max:"+max(num));
Console.WriteLine("Min:"+ min(num));
}
private int max(int[] num)
{
int x=0;
for (int i = 0; i < num.Length; i++)
{
if (x < num[i])
{
x = num[i];
}
}
return x;
}
private int min(int[] num)
{
int x = 0;
for (int i = 0; i < num.Length; i++)
{
if (x > num[i]||x==0)
{
x = num[i];
}
}
return x;
}
}
}
Output:
[Lab no.11] [Computer Programming]
[Methods]
Task No. 4: Take input of an array in on method and print reverse of that array.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab11_ver4
{
class t4
{
int[] arr = new int[10];
public void task4()
{
Console.WriteLine("******************INPUT*********************");
input(arr);
// Console.Write(arr[2]);
Console.WriteLine("******************OUTPUT*********************");
output(arr);
}
private void input(int[] arr)
{
//Console.Write(arr[1]);
for (int i = 0; i < arr.Length; i++)
{
Console.Write("Enter Array[" +i + "]=");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
}
private void output(int[] arr)
{
Console.Write("Array={");
for (int i = arr.Length-1; i>= 0; i--)
{
Console.Write(arr[i] + ",");
}
Console.WriteLine("}");
}
}
}
Output:
[Lab no.11] [Computer Programming]
[Methods]
Task No. 5: Design a fully functional calculator using function.
Solution:
class task5s
{
int num1, num2;
string oper;
public void t5()
{
intput();
if (oper == "+")
addition();
if (oper == "-")
subtraction();
if (oper == "*")
multiplication();
if (oper == "/")
division();
}
private void addition()
{
Console.WriteLine("num1 + num2="+(num1 + num2));
}
private void subtraction()
{
Console.WriteLine("num1 - num2="+(num1 - num2));
}
private void multiplication()
{
Console.WriteLine("num1 * num2="+num1 * num2);
}
private void division()
{
Console.WriteLine("num1 / num2="+num1 / num2);
}
private void intput()
{
Console.Write("Enter num1:");
num1 = Convert.ToInt16(Console.ReadLine());
Console.Write("Enter num2:");
num2 = Convert.ToInt16(Console.ReadLine());
Console.Write("Enter opertion, \n Press + for add \n press - for subtract \n press * for multiply \n press / for divide \n");
oper = Console.ReadLine();
}
}
}
Output:
[Lab no.11] [Computer Programming]
[Methods]
Task No. 6: Design a WFP of your marks sheet.
Solution:
namespace lab11_ver4
{
class t6
{
string name, clas, school;
int totals,eng, urdu, math, chem, phy,rollno;
public void task6()
{
input();
output();
}
private void output() {
Console.WriteLine("**********************MARKSHEET**********************");
Console.WriteLine(" Name:" + name);
Console.WriteLine(" Roll no:" + rollno);
Console.WriteLine(" Class:" + clas);
Console.WriteLine(" School" + school);
Console.WriteLine("*****************************************************");
// marks();
// total();
Console.WriteLine("English:" + eng);
Console.WriteLine("Urdu" + urdu);
Console.WriteLine("Math:" + math);
Console.WriteLine("Chemistry:" + chem);
Console.WriteLine("Physics" + phy);
Console.WriteLine("-----------------------------------------------------");
Console.WriteLine("Total:" + total());
Console.WriteLine("Percentage" + percent + "%");
Console.WriteLine("*****************************************************");
}
private void input() {
Console.WriteLine("Enter your Name");
name = Console.ReadLine();
Console.WriteLine("Enter your Class");
clas = Console.ReadLine();
Console.WriteLine("Enter your School");
school = Console.ReadLine();
Console.WriteLine("Enter your Rollno");
[Lab no.11] [Computer Programming]
[Methods]
rollno = Convert.ToInt16(Console.ReadLine());
Console.Write("Enter English Marks");
eng = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Urdu Marks");
urdu = Convert.ToInt32(Console.ReadLine())
; Console.Write("Enter Maths Marks");
math = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Chemistry Marks");
chem = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Physics Marks");
phy = Convert.ToInt32(Console.ReadLine());
totals= total();
percent= per();
}
double percent;
private int total()
{
return chem + urdu + math + eng + phy;
}
private double per()
{
return Convert.ToDouble (totals) / 500.0 * 100.0;
}
}
}
Output: