You are on page 1of 10

MODERN PROGRAMMING

TOOLS AND TECHNIQUE – II


(CAP 406)

SUBMITTED TO:
SUBMITTED BY:
Lect. Ramandeep Kaur Dikshit
Kaura
RE3804A11

Page | 1
10800647

COURSE CODE: CAP406


COURSE NAME: Modern Programming Tools & Techniques II
Homework No. 1
PART A
1. According to you what are the features of C# in contrast with
C++ and java?
Ans. 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
 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

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.

2. Write a Program to Find Largest of three No’s. Also make these


no’s in increasing order.
Ans.:
using System;

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).

Ans.: an intermediate language is the language of an abstract machine


designed to aid in the analysis of computer programs. The term comes from
their use in compilers, where a compiler first translates the source code of a
program into a form more suitable for code-improving transformations, as
an intermediate step before generating object or machine code for a target
machine. The design of an intermediate language typically differs from that
of a practical machine language in three fundamental ways:

Page | 5
Each instruction represents exactly one fundamental operation; e.g. "shift-
add" addressing modes common in microprocessors are not present.

Control flow information may not be included in the instruction set.

The number of registers available may be large, even limitless.

.net supports CLS i. e. Common language type. its a microsofts feature to


bring all languages near one roof.When You compile .net code it dosen't
converted into binary language, it converted into IL (Intermidate Language)
also known as MSIL. And from IL to binary language converted at run time,
CLR manages this process. At the runtime also it not converts whole project
at time to binary, only converts that part which is going to execute, this the
performance of project increases. This IL can use any lanuage which is
member of that .net studio. The assemblies (ExE, DLL) are also in IL form.
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.

Example:
using System;

class Program
{
static void Main()
{
int i = 0;
while (i < 10)
{
Console.WriteLine(i);

Page | 6
i++;
}
}
}

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 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

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 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.

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.

5. Write a program that implements dynamic arrays.

Page | 10

You might also like