Академический Документы
Профессиональный Документы
Культура Документы
UNIVERSITY OF KARACHI
Department of Computer Science
Course – Programming Languages Advance
Teacher – Ms. Saima Ashraf
Lab Teacher – Mr. Aziz
MCS – PROGRAMME-2018 (2nd Semester)
Assignments
1|Pa ge
MCS-Previous-2018
C# Programming Language Advance Assignment Objectives
# DATE OBJECTIVE SIGNATURE
2 28 Aug 18 Implementation of DDL commands of SQL with suitable examples [CREATE, ALTER, DROP]
3 28 Aug 18 Implementation of DML commands of SQL with suitable examples [Insert INTO table, Update
table, Delete Table]
4 07 Sep 18 Class
2|Pa ge
{
public partial class Form1 : Form
{
private DataText conDB;
public Form1()
{
InitializeComponent();
conDB = new DataText();
conDB.Path = "d:/abc.txt"; // dont use '\'!!
fillCombo();
}
private void fillCombo()
{
this.combo.Items.Clear();
int temp = conDB.Entries();
if (temp > 0)
{
temp--;
for (int i = 0; i <= temp; i++)
{
string name = "";
conDB.ReadEntrie(i, ref name);
if (name == "")
{
name = "<empty>";
}
this.combo.Items.Add("ID: " + i + " - " + name);
}
combo.SelectedIndex = 0;
}
}
private void button7_Click(object sender, EventArgs e)
{
int temp = conDB.Entries();
MessageBox.Show(temp.ToString());
}
bool result = conDB.ReadEntrie(id, ref str_name, ref str_lastname, ref str_phone, ref str_mail, ref str_web);
txtName.Text = str_name;
txtLastName.Text = str_lastname;
txtPhone.Text = str_phone;
txtMail.Text = str_mail;
txtWeb.Text = str_web;
if (!result) { MessageBox.Show("Invalid record"); }
}
private void button5_Click(object sender, EventArgs e)
{
dgv.Rows.Clear();
dgv.Refresh();
string Path = @"d:/abc.txt"; // dont use '\'!!
string[] lines = File.ReadAllLines(Path);
foreach (var line in lines)
{
string[] value = line.Split(';');
dgv.Rows.Add(value);
}
3|Pa ge
}
}
OUTPUT
4|Pa ge
LAB Assignment #-02
Implementation of DDL commands of SQL with suitable examples [CREATE, ALTER, DROP]
QUIRES
--1(a). Create Database
Create database AEI
--2(a). Alter
Alter Table Employee
Add Designation CHAR(20)
--2(b). Alter..Modify
Alter Table Employee
Alter Column Designation Varchar(100)
--2(c) Alter..DROP
Alter Table Employee
Drop Column Designation
--3 Drop
Drop Database AEI
5|Pa ge
Output
6|Pa ge
LAB Assignment #-03
Implementation of DML commands of SQL with suitable examples [Insert INTO table,
Update table, Delete Table]
QUERIES:
INSERT INTO:
7|Pa ge
UPDATE-SET-WHERE:
DELETE FROM:
TRUNCATE:
8|Pa ge
(Emp_no INT NOT NULL, E_name VARCHAR(20), E_address CHAR(25), E_ph_no VARCHAR(50), Dept_no INT NOT
Null, Dept_name VARCHAR(20), Job_id INT NOT Null, Salary DECIMAL(18,2), PRIMARY KEY(Emp_no));
Write SQL queries for following question:
1. Insert aleast 5 rows in the table.
INSERT INTO employee
VALUES(1,'Ahsan','PECHS','0333558978',1003,'Marketing',5004,55000)
INSERT INTO employee
VALUES(2,'Raheel','Nazimabad','0333558978',1002,'Production',5002,55000)
INSERT INTO employee
VALUES(3,'Fatha','DHA','0333558978',1001,'IT',5001,55000)
INSERT INTO employee
VALUES(4,'Rameez','Malir','0333558978',1004,'Account',5003,45000)
INSERT INTO employee
VALUES(6,'Arsalan','Gulshan','0333558978',1003,'Sales',5005,35000))
2. Display all the information of EMP table.
Select * from employee
3. Display the record of each employee who works in department “IT”.
Select * from employee where Dept_name='IT'
4. Update the city of Emp_no-12 with current city as Nagpur.
update Employee Set E_Address='Nagpur' where emp_no='3'
5. Display the details of Employee who works in department MECH.
SELECT first_name, last_name, employee_id, job_id FROM employees WHERE department_id = (SELECT
department_id FROM departments WHERE location_id = (SELECT location_id
FROM locations WHERE city ='Toronto'));
6. Delete the email_id of employee James.
update Employee Set Email_ID=' ' where e_name='James'
7. Display the complete record of employees working in SALES Department.
Select * from employee where Dept_name='IT'
9|Pa ge
LAB Assignment #-04
class Program
{
static void Main(string[] args)
{
UseStatic.show(2);
UseStatic.show(45);
UseStatic saad = new UseStatic();
saad.k();
}
}
class UseStatic
{
static int a = 3;
static int b;
}
static{
Console.WriteLine("Static block initialized");
b=a*14;
}
void k()
{
Console.WriteLine("K constracotr ");
}
}
10 | P a g e
LAB Assignment #-05
Notepad with the function of New & Open only
namespace NotepadXPDemo
{
public partial class Notepad : Form
{
private string currFileName;
public Notepad()
{
InitializeComponent();
}
if(result== DialogResult.OK)
{
if(Path.GetExtension(openFileDialog.FileName) == ".txt")
MainRichTextBox.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.PlainText);
if (Path.GetExtension(openFileDialog.FileName) == ".rtf")
MainRichTextBox.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.RichText);
this.Text = Path.GetFileName(openFileDialog.FileName) + " - Notepad XP";
}
11 | P a g e
12 | P a g e
LAB Assignment #-06
Notepad with the help of Tool Strip function for New & Open & Save
13 | P a g e
LAB Assignment #-07
Data grid view export in excel
namespace excelapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
14 | P a g e
workbook.SaveAs("c:\\output.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
// Exit from the application
app.Quit();
}
}
}
15 | P a g e
LAB Assignment #-08
Using of Interface
Output
namespace interface1
{
public interface ITransactions
{
// interface members
void showTransaction();
double getAmount();
}
public class Transaction : ITransactions
{
private string tCode;
private string date;
private double amount;
public Transaction()
{
tCode = " ";
date = " ";
amount = 0.0;
}
public Transaction(string c, string d, double a)
{
tCode = c;
date = d;
amount = a;
}
public double getAmount()
{
return amount;
}
public void showTransaction()
{
Console.WriteLine("Transaction: {0}", tCode);
Console.WriteLine("Date: {0}", date);
Console.WriteLine("Amount: {0}", getAmount());
}
}
class Program
{
static void Main(string[] args)
{
Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);
Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);
t1.showTransaction();
t2.showTransaction();
Console.ReadKey();
}
}
}
16 | P a g e
LAB Assignment #-08
Using of String
// Comparing b/w two string
string str1 = "This is test";
string str2 = "This is text";
if (String.Compare(str1, str2) == 0)
{
Console.WriteLine(str1 + " and " + str2 + " are equal.");
}
else
{
Console.WriteLine(str1 + " and " + str2 + " are not equal.");
Console.ReadKey();
if (str.Contains("test"))
{
Console.WriteLine("The sequence 'test' was found.");
}
Console.ReadKey();
// Getting a Substring
string str = "Last night I dreamt of San Pedro";
Console.WriteLine(str);
string substr = str.Substring(23);
Console.WriteLine(substr);
//Joining Strings
string[] starray = new string[]{"Down the way nights are dark",
"And the sun shines daily on the mountain top",
"I took a trip on a sailing ship",
"And when I reached Jamaica",
"I made a stop"};
17 | P a g e
string str = String.Join("\n", starray);
Console.WriteLine(str);
18 | P a g e