Anda di halaman 1dari 10

Homework Title No : 1 Course Code: CAP 406

Course Instructor : Course Tutor: Ms Ramandeep Kaur

Date of Allotment : D.O.S: 07-09-10

Student Roll No. : RE3804B34 Section No.: E3804

Declaration,

I declare that this assignment is my individual work .I have not copied from
any other student’s work or from any other source except where due
acknowledgement in made explicitly in the text, not has any part become
written for me by any other person.
Harmanjot

Evaluator’s comments

Marks Obtained ___________ Out Of ____________


PART A

1. According to you what are the features of C# in contrast with C++ and
java?
Ans:- C# is a distinct language from C++ and java.
C++ and c#
• C++ is designed for general object oriented programming in the days when
the typical computer was a standalone machine running a command line-
based user interface.
C# is designed specifically to work with the .Net and is geared to the
modern environment of Windows and mouse-controlled user interface,
networks and the internet
• C++is a general-purpose programming language with high-level and low-
level capabilities.
C# is a simple, modern, object oriented, and type-safe programming
language derived from C and C++.
• C++ is a statically typed, free-form, multi-paradigm, usually compiled
language supporting procedural programming, data abstraction, object-
oriented programming, and generic programming.
• C++ is regarded as a mid-level language. This indicates that C++ comprises
a combination of both high-level and low-level language features.
C# (pronounced C sharp) is firmly planted in the C and C++ family tree of
languages, and will immediately be familiar to C and C++ programmers. C#
aims to combine the high productivity of Visual Basic and the raw power of
C++.
C# and Java
Java language is designed run on JRE i.e Java Runtime Environment while the C
sharp programming language is designed to run on "Common Language Runtime".
The "Java Runtime Environment" comprises the JVM Java Virtual Machine along
with common set of libraries. Both java and C sharp use garbage collection for
reclaiming memory resources. In both language all instances to the classes are of
type "by reference".

1. Inheritance:
Both programming languages doesn't have doesn't for multiple inheritance.
But these languages have interfaces as a alternative multiple inheritance.
2. Main Method:
In java it is valid to compile a program which doesn't have a main method.
But in C sharp it is not valid to compile a program which doesn't have a
main method.
3. Multithreading:
The Multithreading application of the c sharp programming language is quit
simplified than java programming language.
4. "type parameter static members" is not available in java but it is available in
C#.
5. The .NET run-time allows both managed and unmanaged code, enabling
certain classes of bugs that do not exist in Java's pure managed code
environment but also allows interfacing with existing code.

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;

namespace p2
{
class Program
{
static void Main(string[] args)
{
int a = 2, b = 3, c = 1;
if (a > b && a > c)
{
Console.WriteLine("a is greatest ");
}
else if (b > c)
{
Console.WriteLine("b is greatest");
}
else
{
Console.WriteLine("c is greatest");
}

Console.ReadLine();
}
}
}

3. Elaborate the significance of of intermediate language(IL).

Ans:-

When we compile code that uses the .NET Framework library, we don't
immediately create operating system-specific native code. Instead, we compile our
code into Microsoft Intermediate Language (MSIL) code or the intermediate
language.

This compilation is done by JIT (Just In Time) compiler,means This code isn't
specific to any operating system, and isn't specific to C#. Other .NET languages -
for example, Visual Basic .NET - also compile to this language as a first stage.
This compilation step is carried out by VS when we use it to develop C#
applications.

1. It is cpu independent language.


2. It is only understand by CLR.
3. due this language(MSIL) vb.net application can run on any platform on
which .net framework is present.
4. Write a program to input your name and display output on console
window and messagebox.?
Program:

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

namespace ass1
{
class Program
{
static void Main(string[] args)
{
string name;
Console.WriteLine("enter your name");
name = Console.ReadLine();
Console.WriteLine(" your name is"+" "+name);
Console.ReadLine();

}
}
}

5. write a program to change atleast 10 properties of form at runtime.?


PART B

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.Linq;
using System.Text;

namespace ass2.cs
{
class Program
{
static void Main(string[] args)
{
double mrp, qty, dis;
string prod;
Console.WriteLine("enter the product");
prod = Console.ReadLine();
Console.WriteLine("enter the quantity");
qty = Convert.ToDouble( Console.ReadLine());
Console.WriteLine("enter the MRP");
mrp = Convert.ToDouble(Console.ReadLine());
if (mrp<=500&&qty<=2)
{
dis = 3.5;
Console.WriteLine("discount is"+dis+"%");
}

else if (mrp>500&&mrp<=1000&&qty>2&&qty<=10)
{
dis = 6.5;
Console.WriteLine("discount is"+dis+"%");
}
else if (mrp>1000&&mrp<=5000&&qty>10&&qty<=40)
{
dis = 10;
Console.WriteLine("discount is"+dis+"%");
}
else
{
dis = 14;
Console.WriteLine("discount is" + dis + "%");
}
Console.ReadLine();
}

}
}

Output:
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.Linq;
using System.Text;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int i, b, m, n,st = 1;
for(i=1;i<=1000;i++)
{
n=i;
b=n%10;
n=n/10;
st=1;
while(n>0)
{
m=n%10;
n=n/10;
if(b!=m)
{
st=0;
break;
}
if(st=1)
Console.WriteLine(i);
}
}
}
}
}
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.

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


a particular number in an array.
prog:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace p2
{
class Program
{
static void Main(string[] args)
{
int []arr=new arr[10];
int ele,count,loc,i;
for(int i=1;i<=10;i++)
{
arr[i]=Convert.ToInt32( Console.ReadLine());
}
Console.WriteLine(“enter the element to find”);
ele=Convert.ToInt32(Console.ReadLine());
for(int i=1;i<=10;i++)
{
if(arr[i]=ele)
{
count++;
loc=i;
Console.WriteLine(“number found at location:”+loc);

}
Console.ReadLine();
}
}
}
5. Write a program that implements dynamic arrays.

Prog:
using System.Collections;

class Program
{
static void Main()
{
ArrayList list = new ArrayList();
list.Add("One");
list.Add("Two");
list.Add("Three");
}
}