Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

ASSIGNMENT

OF
Modern Programming Tools
and Techniques-II

SUBMITTED TO:- SUBMITTED BY:-

Mr. P.S Vijayendra Anish Sethi

B.TECH(H)-MBA(CSE)

ROLL NO.- 17

SECTON-RA17B1
Q-1 What standard data types does C Sharp use? Contrast it
with the types in C++?

Ans- C# supports a very similar range of basic types to C++, including int, long,
float, double, char, string, arrays, structs and classes. However, don't assume too
much. The names may be familiar, but many of the details are different. For
example, a long is 64 bits in C#, whereas in C++ the size of a long depends on the
platform (typically 32 bits on a 32-bit platform, 64 bits on a 64-bit platform). Also
classes and structs are almost the same in C++ - this is not true for C#. Finally,
chars and strings in .NET are 16-bit (Unicode/UTF-16), not 8-bit like C++.

The C++ programming language identifies five data types as standard data types:

 Void

 Boolean

 Character

 Integer

 Floating-point

The standard data types and the complex data types within C++ have a series of
attributes, which include:

 C++ Reserved or Key Word

 Domain – the allowed values

 Signage – do they allow negative numbers or only positive numbers

 Size – in terms of the number of bytes of storage used in the memory

 Operations Allowed – i.e. Which operators can I use on the data type

Placing some of the above into a summary table, we get:


Q-2 Does C Sharp support variable argument on method? Explain
with the help of an example.?

Ans- Yes.
using the params keyword. The arguments are specified as a list of arguments of a
specific type, e.g. int. For ultimate flexibility, the type can be object. The standard
example of a method which uses this approach is System.Console.WriteLine().
The params keyword can be applied to a method parameter which is an array. Upon
method invocation, the array elements can be supplied as a comma (,) separated list.
For example, if the method parameter were an array of object, the source code would
be similar to the following:
void paramsExample
(object argument-1,
object argument-n,
params object[ ] variableArguments)
{
foreach (object arg in variableArguments)
{
}
}

Q- 3 What’s the difference between const and read-only?


Ans- readonly variables are can be initilized at compile time but we can assign
values to readonly varialble at once through functions or constructors.

but in case of constant variables once assign a value we can't change value and must
assign value to constant variables at the time of declaration.

as the constant variable is constant over the class,that means,all the objects created for
that class have the same value.
but in case of readonly variables,we can assign different values in the different
instances of the class it contains.
Const – Compile-Time Constant Values

First of all, for those of you who came from the C++ and C# world, const in C# is not the
same as const in that language.  A const in C# can be closest considered like
a #define of a literal value (that is, a value, not a code macro).  Const in C# let's you
define constant values.  In C#, you can declare a const of any type as long as the value
assigned can be fully evaluated at compile time.   For the most part, this limits you to
numeric types, characters, and strings:

Notice that up above, you can concatenate strings or do math on numbers to make new
constant literals.  This works because these expressions can be determined at compile
time.  However, notice thatstring.Empty is not a const field, it is a static readonly
instance, thus it will not allow this to be assigned to a const because it's not a literal
expression. 

Now, remember how I said ANY type as long as the value can be evaluated at compile-
time.  This means that const structs, are impossible because a struct must always call
its constructor first to initialize it.  Therefore you cannot have a const struct of any value.

Q- What is the difference about Switch statement in C Sharp from C++ and C?

Ans- It was a surprise that there was no thread for C++ recipes. Though C++ and C#
are quite similar there are some very key and major differences.
-I find C# resembles the style of java more than that of C++ i many ways.

(I will be following this up with some coding recipes, to hopefully start a C++ reciped
thread)

Method/Function Declarations:
C++:
public:
Constructor() { }
void aMemberFunction() { }
void aFunctionDeclaration();
private:
void someOtherFunction() { }
int aVariable;
C#:
private aVariable;
public void aMemberFunction() { }
public void aFunctionDeclaration();
private void someOtherFunction() { }

Class Declaration:
For those who know what a managed class is:
C++:
__gc class A_Class{ };
*NOTE that C++ classes end with a ;
C#:
automatically done so:
class A_Class{ }
Inheritence:
C++:
will allow multiple inheritence. eg. allows a method to be overriden many times in
subclasses (derived classes).
C#:
supports inheritence, but not multiple, only 1 override per method/function/
Includes:

The switch and case statements help control complex conditional and branching


operations. The switchstatement transfers control to a statement within its body.

SYNTAX-

selection-statement:

switch (expression)statement

labeled-statement:

case constant-expression : statement

default : statement

Control passes to the statement whose case constant-expression matches the value


of switch ( expression ). Theswitch statement can include any number
of case instances, but no two case constants within the same switchstatement can have
the same value. Execution of the statement body begins at the selected statement and
proceeds until the end of the body or until a break statement transfers control out of the
body.

Use of the switch statement usually looks something like this:

switch ( expression )

   declarations 

   .

   case constant-expression : 

      statements executed if the expression equals the 

      value of this constant-expression 

      .

   break; 

   default :

      statements executed if expression does not equal 

      any case constant-expression 

Q-5 What is Method Overriding? How to override a function in C


Sharp?
Ans- Method Overriding if changing the behaviour of function in derived class, defined
in the base class.

To override a method in the derived class declare the function virtual in the base class.

We'll begin with a base class that represents an employee. To keep the example as
simple as possible, we'll give this base class a single method called CalculatePay with
the body of this method doing nothing more than letting us know the name of the
method that was called. This will help us determine which methods in the inheritance
tree are being called later.

class Employee
{
public void CalculatePay()
{
Console.WriteLine("Employee.CalculatePay()");
}
}
new public void CalculatePay()
{
Console.WriteLine("SalariedEmployee.CalculatePay()");
}
}

class Poly1App
{
public static void Main()
{
Poly1App poly1 = new Poly1App();

Employee baseE = new Employee();


baseE.CalculatePay();

SalariedEmployee s = new SalariedEmployee();


s.CalculatePay();
}
}

Compiling and executing this application generates the following output: -

c:\>Poly1App
Employee.CalculatePay()
Salaried.CalculatePay()

Q-6 What is the difference between method parameters and


method arguments? Give an example?
Ans- These two terms are sometimes loosely used interchangeably; in particular,
"argument" is sometimes used in place of "parameter". Nevertheless, there is a
difference. Properly, parameters appear in procedure definitions; arguments appear in
procedure calls.
A parameter is an intrinsic property of the procedure, included in its definition. For
example, in many languages, a minimal procedure to add two supplied integers
together and calculate the sum total would need two parameters, one for each expected
integer. In general, a procedure may be defined with any number of parameters, or no
parameters at all. If a procedure has parameters, the part of its definition that specifies
the parameters is called its parameter list.
By contrast, the arguments are the values actually supplied to the procedure when it is
called. Unlike the parameters, which form an unchanging part of the procedure's
definition, the arguments can, and often do, vary from call to call. Each time a procedure
is called, the part of the procedure call that specifies the arguments is called
the argument list.
For example, the equivalent terms actual argument and actual parameter may be used
instead of argument; and formal argument and formal parameter may be used instead
of parameter.
To better understand the difference, consider the following function written in C:

int sum(int addend1, int addend2)


{
return addend1 + addend2;
}

The function sum has two parameters, named addend1 and addend2. It adds the


values passed into the parameters, and returns the result to the subroutine's caller
(using a technique automatically supplied by the C compiler).

You might also like