Professional Documents
Culture Documents
SUBMITTED TO:
SUBMITTED BY:
Lect. Ramandeep Kaur Dikshit
Kaura
RE3804A11
Page | 1
10800647
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.
Page | 2
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
C# vs C++
With its implementation of C#, Microsoft have given way to some of C++'s nitty-gritty
object-orientated features such as templates, and have also changed the way we create
classes. In this article, Jordan compares and contrasts classes in both C++ and C#. He
focuses on demonstrating how Microsoft has changed certain aspects of creating and using
classes in C# including reference types, virtual functions and polymorphism.
Object-orientated programming has taken us a long way in terms of application design and
development in the last twenty or so years. A program is no longer thought of as a series of
functions, which are executed in sequence (like in the procedural programming paradigm),
but rather as a set of objects where each object exposes certain properties and methods
allowing it to interact with other objects.
Page | 3
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SHIN
{
class Program
{
static void Main(string[] args)
{
int x, y, z;
Console.WriteLine("Enter three numbers");
x = Convert.ToInt32(Console.ReadLine());
y = Convert.ToInt32(Console.ReadLine());
z = Convert.ToInt32(Console.ReadLine());
if (x > y && x > z)
{
Console.Write("First number is greater");
}
else if (y > z)
{
Console.Write("2nd number is greater");
}
else
{
Console.Write("3rd number is greater");
}
int[] d = new int[4];
d[0]=x;
Page | 4
d[1]=y;
d[2]=z;
int i,j=0;
int temp = x;
while (j != 2)
{
for (i = 0; i < 2; i++)
{
if (d[i] > d[i + 1])
{
d[i] = d[i + 1];
d[i + 1] = temp;
}
}
j++;
}
Console.WriteLine("\nAscending numbers are");
Console.Write(d[0]+"\n"+d[1]+"\n"+d[2]);
Console.ReadLine();
}
}
}
3. Elaborate the significance of of intermediate language (IL).
Page | 5
Each instruction represents exactly one fundamental operation; e.g. "shift-
add" addressing modes common in microprocessors are not present.
Example:
using System;
class Program
{
static void Main()
{
int i = 0;
while (i < 10)
{
Console.WriteLine(i);
Page | 6
i++;
}
}
}
namespace t
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter your name ");
string name;
name = Console.ReadLine();
Console.WriteLine("Your name is "+name);
Console.ReadLine();
}
}
}
5. Write a program to change atleast 10 properties of form at run
time.?
Page | 7
Ans.:
PART B
Ans.:
using System;
using System.Collections.Generic;
using System.Text;
namespace t
{
class Program
{
static void Main(string[] args)
{
double total,qs,dis=0,ms=500,mr=400,mb=900,mt=2000;
double mp=1;
int choice;
Console.WriteLine("Enter choice to buy");
Console.WriteLine("1.Soup(MRP=500)");
Console.WriteLine("2.Rice(MRP=500)");
Console.WriteLine("3.Biscuit(MRP=1000)");
Console.WriteLine("4.Tea(MRP=2000)");
Page | 8
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
mp = ms;
break;
case 2:
mp = mr;
break;
case 3:
mp = mb;
break;
case 4:
mp = mt;
break;
}
Console.Write("Enter quantity ");
qs = Convert.ToInt32(Console.ReadLine());
if(mp<=500 && qs<=2)
{
dis = 4.5;
}
else if (mp > 500 && mp < 1000 && qs>2 && qs<10)
{
dis = 8.5;
}
else if (mp > 1000 && mp < 5000 && qs > 10 && qs < 40)
{
dis = 10;
}
else
{
dis = 16;
}
total = (mp-((dis/100)*mp))*qs;
Console.WriteLine("Discount="+dis+"%");
Console.Write("Total bill="+total);
Console.ReadLine();
}
}
}
Page | 9
2. Write a program to find paired numbers in the series from 1 to
1000 using for control statement.
Page | 10