Sei sulla pagina 1di 10

WELCOME TO THE LOVELY UNIVERSITY

Homework Title / No. : _____HOMEWORK2_______Course Code: _406________

Course Instructor: ______________________ Course Tutor (if


applicable): PROF.ROHIT OHRI_

Date of Allotment: ___11/ 1/ 2011__________________ Date of


submission: _24 /1/2011_

Student’s Roll No.___RTB011A01_______ Section No. : _TBO11____


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 acknowledgment is made explicitly in the text, nor has any
part been written for me by another person.

Student’s Signature: _RUPAL


GUPTA
Evaluator’s comments:
_____________________________________________________________________
Marks obtained : ___________ out of ______________________
Content of Homework should start from this page only:

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
Homework No. 2
PART A
1. Question: According to you what are the features of C# in
contrast with C++ and java?

Answers: - C# versus C++

In an important change from C++, C# code does not require header


files. All code is written inline. As touched on above, the .NET
runtime in which C# runs performs memory management, taking care of
tasks like garbage collection. Because of this, the use of pointers in
C# is much less important than in C++. Pointers can be used in C#,
where the code is marked as 'unsafe', but they are only really useful
in situations where performance gains are at an absolute premium.

Speaking generally, the 'plumbing' of C# types is different from that


of C++ types, with all C# types being ultimately derived from the
'object' type. There are also specific differences in the way that
certain common types can be used. For instance, C# arrays are bounds
checked unlike in C++, and it is therefore not possible to write past
the end of a C# array.

C# statements are quite similar to C++ statements. To note just one


example of a difference: the 'switch' statements have been changed so
that 'fall-through' behavior is disallowed. As mentioned above, C#
gives up on the idea of multiple class inheritance. Other differences
relating to the use of classes are: there is support for class
'properties' of the kind found in Visual Basic, and class methods are
called using the . Operator rather than the: operator.

C# and Java

Below is a list of features C# and Java share, which are intended to


improve on C++. These features are not the focus of this article, but
it is very important to be aware of the similarities.

Compiles into machine-independent language-independent code which runs


in a managed execution environment.

• Garbage Collection coupled with the elimination of pointers (in


C# restricted use is permitted within code marked unsafe)
• Powerful reflection capabilities
• No header files, all code scoped to packages or assemblies, no
problems declaring one class before another with circular
dependencies

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
• Classes all descend from object and must be allocated on the heap
with new keyword
• Thread support by putting a lock on objects when entering code
marked as locked/synchronized
• Interfaces, with multiple-inheritance of interfaces, single
inheritance of implementations
• Inner classes
• No concept of inheriting a class with a specified access level
• No global functions or constants, everything belongs to a class
• Arrays and strings with lengths built-in and bounds checking
• The '.' operator is always used, no more ->, :: operators
• null and Boolean/bool are keywords
• All values are initialized before use
• Can't use integers to govern if statements
• Try Blocks can have a finally clause.
2. Ques: Write a Program to Find Largest of three No’s. Also make
these no’s in increasing order.
Answer:- using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bmw
{
class Program
{
static void Main(string[] args)
{
{
int a, b, c;

Console.WriteLine("Enter the value of a: ");


a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value of b: ");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value of c: ");
c = Convert.ToInt32(Console.ReadLine());
if (a > b)
{
if (a > c)
{
System.Console.WriteLine("the largets is :{0}"
, a);
System.Console.ReadLine();
}
else
{
System.Console.WriteLine("the largets is :{0}"
, c);

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
System.Console.ReadLine();
}
}
else
{
if (c > b)
{
System.Console.WriteLine("the largets is :{0}"
, c);
System.Console.ReadLine();
}
else
{
System.Console.WriteLine("the largets is :{0}"
, b);
System.Console.ReadLine();
}

}
}
return;
}
}
}
OUTPUT:

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
3. Ques: Elaborate the significance of intermediate language (IL).

Answer: Intermediate language: - This is the language code generated


by the C# compiler or any .NET-aware compiler. All .NET languages
generate this code. This is the code that is executed during runtime.

We can view this MSIL code with the help of a utility called
Intermediate Language Disassembled (ILDASM). This utility displays the
application's information in a tree-like fashion. Because the contents
of this file are read-only, a programmer or anybody accessing these
files cannot make any modifications to the output generated by the
source code.

To view the MSIL Code for the preceding Hello C# program, open the
Hello.exe file from the ILDASM tool; it can be accessed via the Run
command on the Start menu. We have to locate this tool manually.
Normally, it will be in the Bin folder of the .NET SDK installation.

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
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 Disc
{

class abc
{
static void Main(string[] args)
{

Console.WriteLine("Bill of Garment shop");


int MRP, quantity;
Console.WriteLine("Enter Quantity of the item:");
quantity = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter MRP:");
MRP = Convert.ToInt32(Console.ReadLine());

if (MRP<=500 && quantity<=2)


{
Console.WriteLine("Discount of 3.5%");
}
else if ((MRP>=500||MRP<=1000 )&& (quantity>2 && quantity<=10))
{
Console.WriteLine("Discount of 6.5%");
}

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
else if ((MRP>=1000 && MRP<=5000)&&(quantity>=10 && quantity<=40))
{
Console.WriteLine("Discount of 10%");
}
else
{
Console.WriteLine("Discount of 14%");
}
Console.ReadLine();

}
}
}
OUTPUT:

1. Ques: 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.

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace count123
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string a = textBox1.Text;
int len = a.Length;

int up = 0, cha = 0, lw = 0, num = 0, sp = 0, ss = 0;


char[] cc = new char[len];
for (int i = 0; i < a.Length; i++)
{

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
cc[i] = a[i];
}
int asci;
for (int i = 0; i < len; i++)
{
asci = cc[i];
if (asci >= 65 && asci <= 90)
{
up++;
cha++;
}
else if (asci >= 97 && asci <= 122)
{
lw++;
cha++;
}
else if (asci >= 48 && asci <= 57)
{
num++;
}
else if (asci == 32)
{
sp++;
}
else
{
ss++;
}
}
MessageBox.Show("The number of words is" + len);
MessageBox.Show("THe number of character is" + cha);
MessageBox.Show("The number of upper case is" + up);
MessageBox.Show("Lower case" + lw);
MessageBox.Show("numbers is " + num);
MessageBox.Show("Spaces is " + sp);
MessageBox.Show("Special Character" + ss);

}
}
}

2. Ques: Write a program that implements dynamic arrays.


Answer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication12
{
class sid
{

WELCOME TO THE LOVELY UNIVERSITY


WELCOME TO THE LOVELY UNIVERSITY
static void Main(string[] args)
{
ArrayList myList=new ArrayList();
int i;

for (i = 0; i < 15; i++)


{
myList.Add(i);

}
foreach (int j in myList)
{
Console.WriteLine(j);
}
Console.ReadLine();
}
}
}
OUTPUT:

WELCOME TO THE LOVELY UNIVERSITY

Potrebbero piacerti anche