csharp2
TRANSCRIPT
![Page 1: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/1.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 1/10
WELCOME TO THE LOVELY UNIVERSITY
Homework Title / No. : _____HOMEWORK2_______Course Code: _406________
Course Instructor: ______________________ Course Tutor (ifapplicable): PROF.ROHIT OHRI_
Date of Allotment: ___11/ 1/ 2011__________________ Date ofsubmission: _24 /1/2011_
Student’s Roll No.___RTB011A01_______ Section No. : _TBO11____ Declaration:I declare that this assignment is my individual work. I have notcopied from any other student’s work or from any other source exceptwhere due acknowledgment is made explicitly in the text, nor has anypart been written for me by another person.
Student’s Signature: _RUPALGUPTA
Evaluator’s comments:_____________________________________________________________________Marks obtained : ___________ out of ______________________Content of Homework should start from this page only:
WELCOME TO THE LOVELY UNIVERSITY
![Page 2: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/2.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 2/10
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 headerfiles. All code is written inline. As touched on above, the .NETruntime in which C# runs performs memory management, taking care oftasks like garbage collection. Because of this, the use of pointers inC# 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 usefulin 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 thatcertain common types can be used. For instance, C# arrays are boundschecked unlike in C++, and it is therefore not possible to write pastthe end of a C# array.
C# statements are quite similar to C++ statements. To note just oneexample of a difference: the 'switch' statements have been changed sothat 'fall-through' behavior is disallowed. As mentioned above, C#gives up on the idea of multiple class inheritance. Other differencesrelating 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 toimprove on C++. These features are not the focus of this article, butit is very important to be aware of the similarities.
Compiles into machine-independent language-independent code which runsin a managed execution environment.
• Garbage Collection coupled with the elimination of pointers (inC# restricted use is permitted within code marked unsafe)
• Powerful reflection capabilities
• No header files, all code scoped to packages or assemblies, noproblems declaring one class before another with circulardependencies
WELCOME TO THE LOVELY UNIVERSITY
![Page 3: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/3.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 3/10
WELCOME TO THE LOVELY UNIVERSITY
• Classes all descend from object and must be allocated on the heapwith new keyword
• Thread support by putting a lock on objects when entering codemarked as locked/synchronized
• Interfaces, with multiple-inheritance of interfaces, singleinheritance 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
![Page 4: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/4.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 4/10
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
![Page 5: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/5.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 5/10
![Page 6: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/6.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 6/10
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
![Page 7: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/7.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 7/10
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
![Page 8: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/8.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 8/10
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
![Page 9: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/9.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 9/10
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
![Page 10: CSHARP2](https://reader031.vdocument.in/reader031/viewer/2022021117/577d2e921a28ab4e1eaf6bee/html5/thumbnails/10.jpg)
8/7/2019 CSHARP2
http://slidepdf.com/reader/full/csharp2 10/10
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