14
HOMEWORK TITLE NO-1 COURSE CODE-CAP 406 COURSE INSTRUCTOR- MISS.RAMANDEEP KAUR  D.O.S-07/09/2010 STUDENT ROLLNO-13 SECTION NO-E3804A13 DECLARATION: I declare that this ASIGNMENT is my individual work. I have not copied from other students work or from any other source except where due acknowledgement is made explicitly in the text, not has any part being written for me by another person.  STUDENT’S SIGNATURE AMITA RAI Evaluator comments……………. Marks obtained…………..out of……………..  

e3804a13

Embed Size (px)

Citation preview

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 1/14

HOMEWORK TITLE NO-1 COURSE CODE-CAP 406

COURSE INSTRUCTOR- MISS.RAMANDEEP KAUR 

 

D.O.S-07/09/2010

STUDENT ROLLNO-13 SECTION NO-E3804A13

DECLARATION: I declare that this ASIGNMENT is my individual work. I havenot copied from other students work or from any other source except where due

acknowledgement is made explicitly in the text, not has any part being written for 

me by another person.

 

STUDENT’S SIGNATURE

AMITA RAI

Evaluator comments…………….

Marks obtained…………..out of……………..

 

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 2/14

PART A

Q.1: - According to you what are the features of C# in contrast with C++ and

 java?

ANS: - Features of c# and java:-

Data types Java C#

Signed integers Yes; 8, 16, 32, 64 bits Yes; 8, 16, 32, 64 bits

Unsigned integers No Yes; 8, 16, 32, 64 bits

Character Yes YesBoolean type Yes Yes

Reference types Yes Yes

Arrays Yes Yes

Garbage collection Yes Yes

Weak references Yes Yes

Soft references Yes No

• C++ is a combination of high-level and low-level language features. While

C# is work with the .Net and is geared to the modern environment of 

Windows.

• C# is an object oriented language derived from C and C++.

C++ defines 3 access levels: PRIVATE BASE: A base class declared private in a derived class. Due

to this public members are accessible only from their derived class.

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 3/14

PUBLIC BASE: A base class is declared public in a derived class. Due

to this the public members are accessible to the users of that particular 

derived class.

PROTECTED BASE: A base class is declared protected in a derived

class, such that the public and protected both members are accessible in

that derived class.

C# does not include checked exceptions. Some would argue that checked

exceptions are very helpful for good programming practice. They were to some

extent an experiment in Java.

Java requires that a source file name must match the only public class inside it,

while C# allows multiple public classes in the same file.• C# defines 5 access modifiers for class members:

Private, protected, internal, protected internal and public.

Private is the default such that these are accessible only to the class in

which it is defined.

A member declared as protected is accessible to the class wherein it is

declared and also in any classes which derive from that class.

The internal access modifier specifies that the member is accessible toany classes defined in the same assembly.

A member declared as protected internal will be accessible by any

derived class as well as any classes defined in the same assembly.

A public member is accessible to all.

Q.2: - Write a Program to Find Largest of three No’s. Also make these no’s in

increasing order.

ANS: - using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 4/14

namespace test1

{

class Program

{

static void Main(string[] args)

{

int [ ] arr = new int[3];

Console.WriteLine("Enter x");

arr[0] = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter y");arr[1] = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter z");

a[2] = Convert.ToInt32(Console.ReadLine());

if (arr[0] > arr[1] && arr[0] > arr[2])

{

Console.WriteLine("The largest no is " + arr[0]);

}

else if (arr[1] > arr[0] && arr[1] > arr[2])

{

Console.WriteLine("The largest no is " + arr[1]);

}

else

{

Console.WriteLine("The largest no is " + arr[2]);

}

for (int x = 0; x < arr.Length; x++)

{

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 5/14

for (int y = 0; y < arr.Length - 1; y++)

{

if (arr[y] > arr[y + 1])

{

int tem;

tem = arr[y + 1];

arr[y + 1] = arr[y];

arr[y] = tem;

}

}}

for (int x = 0; x < arr.Length; x++)

Console.WriteLine(arr[x]);

Console.ReadLine();

}

}

}

 

Q.3: - Elaborate the significance of of intermediate language(IL).

ANS: - IL is an implementation of the Common Intermediate Language (CIL), a

key element of the EMCA CLI specification. IL was invented first and it is

  programming language neutral. It was then followed by other programming

languages like C#, Visual Basic.NET, ASP.NET, etc. IL supports all object-

oriented features, including data abstraction, inheritance, polymorphism, and

events. .NET supports multiple languages and multiple platforms, as long as the

target platforms have a CLR. We can develop a valid .NET assembly using the

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 6/14

supported IL instructions and features. .NET compatible language is finally

converted to either Assembler or Intermediate Language (IL).

.net supports CLS i. e. Common language type. It is a Microsoft feature to bring all

languages near one roof. When you compile .net code it doesn’t converted into

 binary language, it converted into IL (Intermediate Language) also known as

MSIL.

This IL can use any language which is member of that .net studio. The assemblies

(ExE, DLL) are also in IL form. So u can use any EXE or DLL created in vb.net in

c#.net also. Basically IL is a part of .NET framework. The intermediate code is the

 basis of the compilation of every program in c#.

Q.4: - Write a program to input your name and display output on console

window and message box?

ANS: -using System;using System.Collections.Generic;

using System.Linq;using System.Text;namespace test2{

class Program{

static void Main(string[ ] args){

string s;Console.WriteLine("Enter any string");s = Console.ReadLine();

Console.WriteLine(" string is = " +s);Console.ReadLine();}

}}

Q.5: - write a program to change at least 10 properties of form at runtime?

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 7/14

 

PART B

Q.1: - Write a Program to Print Sale Bill of a Garment House, with following

terms of discount on each product :-

• if MRP is less than or equals to 500 and quantity sold is less

than or equals to 2 Mtr, then discount = 3.5%

• if MRP is greater than 500 and less than or equals to 1000 and

quantity sold is more than 2 mtr and less than or equals to 10 Mtr,

then discount = 6.5%

• if MRP is greater than 1000 and less than or equals to 5000

and quantity sold is more than 10 mtr and less than 40 mtr., then

discount = 10%

• Otherwise discount is 14%.

ANS: - 

using System;

using System.Collections.Generic;

using System.Text;namespace test3

{

 

class Program

{

static void Main(string[ ] args)

{

Console.WriteLine(" bill of garment house");

Int price, q;

Console.WriteLine("Enter Quantity:");

q = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter Maximum Price:");

price = Convert.ToInt32(Console.ReadLine());

 

if (price<=500 && q<=2)

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 8/14

{

Console.WriteLine("Discount is= 3.5%");

}

else if ((price>=500||price<=1000 )&& (q>2 && q<=10))

{ Console.WriteLine("Discount is = 6.5%");

}

elseif ((price>=1000 && price<=5000)&&(q>=10 && q<=40))

{

Console.WriteLine("Discount is = 10%");

}

else

{

Console.WriteLine("Discount is = 14%");

}Console.ReadLine();

}

}

}

Q.2: - Write a program to find paired numbers in the series from 1 to 1000

using for control statement.

ANS: -

using System;

using System.Collections.Generic;

using System.Text;

namespace test4

{

 

class Program

{static void Main(string[ ] args)

{

int x,y,z,n;

for (int i = 10; i <= 1000; i++)

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 9/14

{

if (i > 10 && i <= 99)

{

n = i;

x= n % 10;

n = n / 10;

y = n;

if (x == y)

{

Console.WriteLine(i);

}

}

if (i >= 100 && i <= 999)

{

n= i;

x = n % 10;

n = n / 10;

y= n % 10;

n = n / 10;

z= n;

if (x == y && x == z)

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 10/14

{

Console.WriteLine(i);

}

}

Console.ReadLine();

}

}

}

Q.3: - Write a Program to count total lines, words, characters, Uppercase

alphabets, lowercase alphabets, numbers , spaces and special symbols typed

by user in a text box.

ANS: - 

using System;

using System.Collections.Generic;

using System.Text;

namespace test5

class Program

{

static void Main(string[ ] args)

{

Console.WriteLine("Enter the string");

string s=Console.ReadLine();

int len=s.Length;int up=0,cha=0,lw=0,num=0,sp=0,ss=0;

char[] cc=new char[len];

for (int i = 0; i < s.Length; i++)

{

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 11/14

cc[i] = s[i];

}

int ascii;

for (int i = 0; i < len; i++)

{

ascii = cc[i];

if (ascii >= 65 && ascii <= 90)

{

up++;

cha++;}

else if (ascii >= 97 && ascii <= 122)

{

lw++;

cha++;

}

else if (ascii >= 48 && ascii <= 57)

{

num++;

}

else if (ascii == 32)

{

sp++;

}

else

{

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 12/14

ss++;

}

}

Console.WriteLine("number of words is"+len);

Console.WriteLine(“ number of character is"+cha);

Console.WriteLine(" number of upper case is"+up);

Console.WriteLine("Lower case"+lw);

Console.WriteLine("numbers is "+num);

Console.WriteLine("Spaces are "+sp);

Console.WriteLine("Special Character are"+ss);Console.ReadLine();

}

}

}

 

Q.4: - Write a Program that finds the location and number of occurrences of 

a particular number in an array.

ANS: - using System;using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace test5

{

 

class Program

{ static void Main(string[] args)

{

 

Console.WriteLine("enter size of an array");

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

int[] arr = new int[s];

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 13/14

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

{

Console.WriteLine("enter" + i+" element");

arr[i] = Convert.ToInt32(Console.ReadLine());

}Console.WriteLine("enter number to search:");

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

int ocur = 0;

String s1=String.Empty;

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

{

if (flag==s1[i])

{

ocur++;

s1+=" "+i+",";}

}

Console.WriteLine(f + " occurs " + occur + " times in Array at

 postions"+s1);

Console.ReadLine();

}

}

}

Q.5: - Write a program that implements dynamic arrays.

ANS: - using System;

using System.Collections.Generic;

using System.Collections;

namespace test6

{

class Program

{

public static void Main(string[] args){

ArrayList arr=new ArrayList();

int x;

 

for (x = 0; x < 10; x++)

{

8/8/2019 e3804a13

http://slidepdf.com/reader/full/e3804a13 14/14

arr.Add(x);

 

}

foreach (int i in arr)

{ Console.WriteLine(i);

}

Console.ReadLine();

}

}

}