You are on page 1of 26

Chapter 1 Case Study

Problem Statement
WebDev Enterprises is a medium sized company that develops Web applications using
J2EE technology for its overseas clients such as BlueSoft Software Solutions and
InterSolutions rivate !imited" #he management at WebDev recently conducted an
analysis and discovered that it has not been able to use the code of its e$isting
applications developed in J2EE when developing new J2EE applications" %s a result& the
deadlines for the new pro'ects were not being met causing financial loss to WebDev
Enterprises" Because of not being able to meet deadlines& WebDev Enterprises was losing
its clients" In addition& the management of WebDev Enterprises found that it was a
comple$ tas( to develop applications in J2EE" )ow can the management of WebDev
solve the problem*

Solution
In order to be able to reuse the code of e$isting applications& WebDev must start creating
Web based applications using +, and %S"-E#" +, provides features such as
inheritance and interface that allow reusability of code" #his means that code written
for a specific application in +, can be easily used for another +, application"
Inheritance feature of +, allows a class to inherit properties& which contain data and
methods of another class" .or e$ample& if you create a class % and define certain
properties such as name and address in it& and a display method to display the values
contained in the properties& then you can use the properties and methods of % class in
another class B"
Interfaces in +, allow you to declare abstract methods" #hese interfaces can be
implemented in multiple classes" Each class in which the interface is implemented
can contain specific code for the abstract methods defined in the interface" #hus&
with the use of +, features such as Inheritance and Interface& code of one +,
application can be reused in another +, application" %s a result& development time
for creating an application in +, is reduced"
With the use of +,& programmers wor(ing at WebDev Enterprises could develop
applications efficiently and in less time"
+, programming language is supported by /icrosoft 0isual Studio 2112& which is a
rapid development tool for developing Windows based and Web based applications"
#he support for "-E# .ramewor( in +, allows you to create interactive user
interfaces for applications in less time" #he "-E# .ramewor( provides the +ontrol
class that helps use controls& their properties and methods to develop interactive user
interfaces for an application in less time"
Because of all these reasons& which include +, support in /icrosoft 0isual Studio 2112
and inheritance& the programmers wor(ing in WebDev were able to meet the
deadlines for the new pro'ects and satisfy the re3uirements of the overseas clients"
%S"-E# is a technology supported by /icrosoft 0isual Studio 2112" It helps in rapid
development of Web based applications" %S"-E# also supports +, programming
language for development of Web based applications" In %S"-E#& programmers at
WebDev Enterprises can use the controls available in /icrosoft 0isual Studio 2112
through the /icrosoft "-E# framewor(" #he controls available in 0isual Studio
2112 and supported by %S"-E# can be used to create graphical user interface for
Web based applications in less amount of time"
#hus& with the use of +, and %S"-E#& WebDev has been able to solve its problem and
rapidly develop applications for its overseas clients"

Chapter 3 Case Study
Problem Statement
%4art Enterprise is a manufacturing unit that is involved in the manufacturing of
automobile parts" #his company was established in 5671 and since then the staff of
%uart has been manually (eeping the records of manufacturing parts" -ow& it has been
discovered by the management of %4art Enterprise that manual record (eeping results
in occurrence of a large number of errors" In addition& it has also been discovered that
manually (eeping records of manufactured parts is time consuming" )ow can
management of %uart Enterprise automate the tas( of maintaining records of
manufactured parts*
Solution
%fter much research& the management of %4art Enterprise comes to the conclusion that
an application created in a high level programming language such as +, is needed to
automate the tas( of maintaining the records of manufactured parts" 8uic( Soft
Solutions rivate !imited& which is a software development company& is contacted
by %4art Enterprise to develop the application for automating the tas( of
maintaining the records of manufactured parts" #he team of programmers at 8uic(
Soft Solutions rivate !imited first conducted an interview with the staff of %4art
Enterprise to find out their re3uirements" %fter re3uirement analysis& it was decided
by the programmers at 8uic( Soft Solutions rivate !imited that +, features such as
constructors and variables must be used in the application for automating the tas( of
(eeping records of manufactured parts9
using System;
using System.Collections;
class Inventory {
string partName;
double partPrice;
int priceQty;
public Inventory(string pName, double pPrice, int pQty) {
partName pName;
partPrice pPrice;
priceQty pQty;
Console.!rite"ine(#$nP%&' N%() * {+,,-+.#,partName);
Console.!rite"ine(#$tPrice * &s.{+,/. $n$tQuantity*
{-.#,partPrice, priceQty);
.
.
public class Stoc01ata {
public static void (ain() {
Console.!rite"ine(#%2C Spare Parts "td. Stoc0 "ist#);
ne3 Inventory(#2olts#, 4.4/, -++);
ne3 Inventory(#S5oc0ers#, /.4/, 6+);
ne3 Inventory(#2ra0e Pads#, 6./+, /+);
ne3 Inventory(#Steering#, -4+, 4+);
.
.
In +,& constructors help initialise the ob'ects of a class and variables are used to store
data related to an ob'ect" #he name of the constructor in +, must be same as the name of
the class"
Chapter 5 Case Study
Problem Statement
/artin is wor(ing as a 'unior programmer in )igh.i Software Solutions& which is a
software development company involved in developing applications in +& Java and
+, programming languages" #he ro'ect /anager of /artin has as(ed him to create
an application for converting a number into its e3uivalent binary format" /artin has
to develop the application for an overseas client& #echSoft Solutions" )ow should
/artin create the application*
Solution
#o satisfy the overseas client& /artin should use an ob'ect oriented language such as +,
to create the application for converting a number into binary format" +, provides bitwise
operators that can be easily used in a +, application to perform manipulation on binary
data" %fter much research& /artin develops the following application in +, for
automating the tas( of converting a number into binary format9
using System;
class Convert {
public int nobits;
public Convert(int n) {
nobits n;
.
public void Convert'o2inary(int num) {
int mas0 -;
mas0 77 nobits,-;
int space8al +;
9or(; mas0 : +; mas0 ;; -)
{
i9((num < mas0) : +)
Console.!rite(#-#);
else
Console.!rite(#+#);
space8al==;
i9((space8al > ?) +)
{
Console.!rite(# #);
space8al +;
.
.
Console.!rite"ine();
.
.
public class 2it!ise1emo {
public static void (ain() {
Console.!rite"ine(#)nter a Number 9or Conversion to 2inary @orm* #);
int numint.Parse(Console.&ead"ine());
Convert con ne3 Convert(?);
Console.!rite"ine(#'5e Number in 2inary @orm is* #);
con.Convert'o2inary(num);
.
.
#he bitwise operators can be easily used in a +, application to shift the bits from left to
right and vice versa" /anually performing the tas( of bit manipulation is time
consuming and error prone"
Chapter 7 Case Study
Problem Statement
St eters School is a convent school that provides education from :"; class to 52
th
class"
8uarterly& half yearly and final e$ams are conducted every year for students of all classes
in St eters School" #he class teacher of each class has to prepare a student report for
every student after a particular e$am has been conducted" <ecently& it has been found by
the principal of St eters School that a lot of time is being ta(en by the class teacher in
preparing the student reports" #he principal has also found out that the efficiency of the
teachers have decreased because they have been manually performing the tas( of
preparing the student reports for each student" St eters have =11 students studying in its
different classes" reparing student report for at least >1 students per class has become a
tedious tas( for the class teacher of a specific class" )ow can the principal of St eters
School solve the problem of the teachers*
Solution
%fter holding meetings with senior teachers of the school& the principal of St eters
School has come to the conclusion that the tas( of calculating total mar(s for
preparing a student report must be automated through a software application running
on a computer system" %fter coming to this conclusion& the principal of St eters
School as(s -andita& who is teaching computer science to students of higher classes
such as 6
th
& 51
th
& 55
th
and 52
th
to create the application for automating the tas( of
calculating total mar(s that is performed by class teachers while preparing student
report" .or this& -andita first conducts an interview with the class teachers of
different classes to understand their re3uirements" %fter the analysis of the
re3uirements& -andita decides to use decision ma(ing and looping concept of +, in
an application to automate the tas( of calculating the total mar(s for each student of
a class" Decision ma(ing and looping allows a programmer to decide the flow of
control for a program or application" -andita creates the following application for
automating the tas( of calculating total mar(s9
using System;
class Student(ar0s
{
static void (ain(stringAB args)
{
intAB mar0s ne3 intA/B;
int total(ar0s +;
Console.!rite"ine(#Student In9ormation$n#);
9or (int i +; i 7 /; i==)
{
Console.!rite"ine(#)nter Cour (ar0s In SubDect {+.* #,i=-);
mar0sAiB int.Parse(Console.&ead"ine());
.
Console.!rite"ine();
EE 1isplaying Student (ar0s
Console.!rite(#'5e mar0s you 5ave entered are* #);
9or (int i +; i 7 /; i==)
{
i9(i7F)
Console.!rite(mar0sAiB = #, #);
else
Console.!rite(mar0sAiB);
.

EE Calculating and 1isplaying 'otal (ar0s o9 t5e Student
9or (int i +; i 7 /; i==)
{
total(ar0s = mar0sAiB;
.
Console.!rite"ine();
Console.!rite"ine(#Cour total mar0s are* {+.#, total(ar0s);
EE Calculating and 1isplaying (aGimum (ar0s o9 t5e Student
int maG(ar0s mar0sA+B;
int indeG-;
9or (int i -; i 7 mar0s."engt5; i==)
{
i9 (mar0sAiB ; maG(ar0s)
{
maG(ar0s mar0sAiB;
indeGi=-;
.
.
Console.!rite"ine(#Cou 5ave scored t5e maGimum mar0s {+. in
SubDect {-..#, maG(ar0s,indeG);
EE Calculating and 1isplaying (inimum (ar0s o9 t5e Student
int min(ar0s mar0sA+B;
indeG-;
9or (int i -; i 7 mar0s."engt5; i==)
{
i9 (mar0sAiB 7 min(ar0s)
{
min(ar0s mar0sAiB;
indeGi=-;
.
.
Console.!rite"ine(#Cou 5ave scored t5e minimum mar0s {+. in
SubDect {-..#, min(ar0s,indeG);
EE Calculating and 1isplaying Percentage o9 t5e Student
double percentage;
double val+.+;
val(double)total(ar0s E /++;
percentage (double) valH-++;
Console.!rite"ine(#Cour percentage is* {+.>#, percentage);
Console.&ead"ine();
.
.
In looping& a set of program staements are e$ecuted based on a condition" #he program
statements are e$ecuted until a specific condition is true" When the condition becomes
false the e$euction of the program statements is terminated"

Chapter 9 Case Study
Problem Statement
B"; International School is an educational institute that provides primary education to
children from :"; class to 51
th
class" #he administrative staff of B"; International School
has to maintain the records& which include name& class and rollno of students studying in
different classes" /anually maintaining the record of each student is a tedious process for
the administrative staff of B"; International School" % large number of errors occur when
the administrative staff enters the records manually in registers" )ow can B";
International School automate the tas( of entering student records*
Solution
In order to ma(e the process of maintaining student records easy and efficient& B";
International School contacts SoftDev software development organisation to create an
application& which will help in the tas( of entering the student records" SoftDev assigns
the tas( of creating the application for B"; International School to Siddarth& who is a
senior programmer in the organisation" Siddarth decides to use the +, programming
language for creating the application to enter student records" +, provides the %rray!ist
class in the System"+ollections namespace" #his %rray!ist class allows you to create an
array list& which can store array ob'ects" #he size of the array list is fi$ed at run time"
#hus the array list created using %rray!ist class is a dynamic array list" Because a large
amount of data has to be entered in case of B"; International School& use of array list will
be helpful for Siddarth"

%fter understanding the re3uirements of B"; International School& Siddarth develops the
following +, application
using System;
using System.Collections;
using System.Collections.Ieneric;
using System.'eGt;
namespace %ddStudent1etails
{
class Student1etails
{

static void (ain(stringAB args)
{
string studname-, studname4, studname6;
string classname-, classname4, classname6;
string rollno-, rollno4, rollno6;
string getresult;
%rray"ist arrlist ne3 %rray"ist();
Console.!rite"ine(#'5e initial capacity o9 arraylist # =
arrlist.Capacity);
Console.!rite"ine(#'5e initial elements are # =
arrlist.Count);
Console.!rite"ine(#)nter 1etails o9 Student -#);
Console.!rite"ine(#JJJJJJJJJJJJJJJJJJJJJJJJJJJJJ#);
Console.!rite(#)nter Name o9 Student- * #);
studname- Console.&ead"ine();
Console.!rite(#)nter Class o9 Student- * #);
classname- Console.&ead"ine();
Console.!rite(#)nter &oll No. o9 Student- * #);
rollno- Console.&ead"ine();
Console.!rite"ine(#JJJJJJJJJJJJJJJJJJJJJJJJJJJJJ#);
Console.!rite(#)nter Name o9 Student4 * #);
studname4 Console.&ead"ine();
Console.!rite(#)nter Class o9 Student4 * #);
classname4 Console.&ead"ine();
Console.!rite(#)nter &oll No. o9 Student4 * #);
rollno4 Console.&ead"ine();
Console.!rite"ine(#JJJJJJJJJJJJJJJJJJJJJJJJJJJJJ#);
Console.!rite(#)nter Name o9 Student6 * #);
studname6 Console.&ead"ine();
Console.!rite(#)nter Class o9 Student6 * #);
classname6 Console.&ead"ine();
Console.!rite(#)nter &oll No. o9 Student6 * #);
rollno6 Console.&ead"ine();
Console.!rite"ine(#JJJJJJJJJJJJJJJJJJJJJJJJJJJJJ#);
arrlist.%dd(studname-);
arrlist.%dd(classname-);
arrlist.%dd(rollno-);
arrlist.%dd(studname4);
arrlist.%dd(classname4);
arrlist.%dd(rollno4);
arrlist.%dd(studname6);
arrlist.%dd(classname6);
arrlist.%dd(rollno6);
Console.!rite"ine(#Current Capacity# = arrlist.Capacity);
Console.!rite"ine(#%rray"ist 5aving elements # =
arrlist.Count);
Console.!rite(#%rray"ist is 5aving content*,#);
9or (int i +; i 7 arrlist.Count; i==)
{
Console.!rite(arrlistAiB = # #);
.
Console.!rite"ine(#$n#);
Console.!rite"ine(#'o remove 4nd student details press y or
to interc5ange student details- 3it5 student details6 press n.#);
getresult Console.&ead"ine();
i9 (getresult #y#)
{
Console.!rite"ine(#&emoving 4nd Student details#);
Console.!rite"ine(#JJJJJJJJJJJJJJJJJJJJJJJJJJJ#);
arrlist.&emove(studname4);
arrlist.&emove(classname4);
arrlist.&emove(rollno4);
Console.!rite"ine(#Current Capcity o9 t5e arraylist is
no3 # = arrlist.Capacity);
Console.!rite"ine(#%rraylist is 5aving elements# =
arrlist.Count);
Console.!rite(#'5e elements o9 %rraylist are no3*,#);
9or (int m +; m 7 arrlist.Count; m==)
{
Console.!rite(arrlistAmB = # #);
.
Console.!rite"ine(#$n#);
.
else
{
Console.!rite"ine(#$n#);
Console.!rite"ine(#C5anging elements#);
Console.!rite"ine(#JJJJJJJJJJJJJJJJJJJJJJJJJJJ#);
arrlistA+B studname6.'oString();
arrlistA-B classname6;
arrlistA4B rollno6;
arrlistAKB studname-;
arrlistALB classname-;
arrlistA?B rollno-;

Console.!rite(#No3 t5e elements o9 t5e %rray"ist are *
#);
9or (int m +; m 7 arrlist.Count; m==)
{
Console.!rite(arrlistAmB = # #);
.
Console.!rite"ine(#$n#);
.
.

.
.
With the use of +, application created by Siddarth& the administrative staff of B";
International will be able to save time in entering the details such as name and class of
students studying in different classes"
Chapter 11 Case Study
Problem Statement
+omp#ech is a medium sized organisation that is involved in sale of computer hardware"
It also has a small software development department& which develops customised
software and Web sites for different organisations" +omp#ech has been till now manually
maintaining the records of its employees& which is time consuming and decreases the
efficiency of the )"< department staff" " )ow can +omp#ech solve the problem*
Solution
+omp#ech re3uests one of the programmer& )arsh& who has been wor(ing for past two
years in the software development department& to create an application& which will enable
the )"< department to automate the tas( of entering employee data" In order to
'udiciously utilise memory space& )arsh decides to use structure feature of +," %
structure is a value type that allows you to organise related data of different data types"
%fter much research& )arsh creates the following +, application9
using System;
using System.Collections.Ieneric;
using System.'eGt;
namespace Structure)Gample
{
public struct )mployee
{
private string empJdetails;
public string !rite
{
get { return empJdetails; .
set { empJdetails value; .
.
public string &ead()
{
return Console.&ead"ine();
.
.
public struct )mployee1etails
{
)mployee name;
)mployee address;
)mployee telep5one;
)mployee dept;
)mployee sal;

public )mployee Name
{
get { return name; .
set { name value; .
.
public )mployee %ddress
{
get { return address; .
set { address value; .
.
public )mployee 'elep5one
{
get { return telep5one; .
set { telep5one value; .
.
public )mployee 1epartment
{
get { return dept; .
set { dept value; .
.
public )mployee Salary
{
get { return sal; .
set { sal value; .
.
public void S5o3%ll1etails()
{
)mployee emp ne3 )mployee();
Console.!rite"ine(#)mployee 1etails &egistration System.#);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#);
Console.!rite(#)nter t5e Name o9 t5e )mployee* #);
name.!rite emp.&ead();
Console.!rite(#)nter t5e %ddress o9 t5e )mployee* #);
address.!rite emp.&ead();
Console.!rite(#)nter t5e 'elep5one o9 t5e )mployee* #);
telep5one.!rite emp.&ead();
Console.!rite(#)nter t5e 1epartment o9 t5e )mployee* #);
dept.!rite emp.&ead();
Console.!rite(#)nter t5e Salary o9 t5e )mployee* #);
sal.!rite emp.&ead();
.
.

class S5o3)mployee1etails
{
static void (ain(stringAB args)
{
string input ##;
)mployee1etails emp- ne3 )mployee1etails();
emp-.S5o3%ll1etails();
Console.!rite"ine();
Console.!rite"ine(#S5o3ing )mployee 1etails#);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,,,,,,,,,,,#);
Console.!rite"ine(#Name* {+.#, emp-.Name.!rite);
Console.!rite"ine(#%ddress* {+.#, emp-.%ddress.!rite);
Console.!rite"ine(#'elep5one* {+.#, emp-.'elep5one.!rite);
Console.!rite"ine(#1epartment* {+.#, emp-.1epartment.!rite);
Console.!rite"ine(#Salary* {+.#, emp-.Salary.!rite);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#);
Console.!rite"ine(#Press y to save t5e record....#);
input Console.&ead"ine();
i9 (input #y#)
{
Console.!rite"ine(#&ecord Saved.#);
.
else
{
Console.!rite"ine(#&ecord not saved.#);
.

.
.
.
#he use of structure in a +, application allows you to manage the memory of a computer
efficiently as all related data is organised in a structure" It also increases the performance
of a +, application"
Chapter 13 Case Study
Problem Statement
%rchBuild is a small organisation& which is involved in creating architectural designs for
buildings such as homes& hospitals and educational institutes" While ma(ing the
architectural designs& the architects wor(ing in %rchBuild need to calculate the area of
different shapes such as rectangle& circle and s3uare" #ill now& these architects have been
calculating areas manually using calculator for comple$ calculations" /anual calculation
of different shapes is time consuming" %s a result& the efficiency of the architects wor(ing
in %rchBuild has decreased considerably" )ow can %rchBuild solve this problem*
Solution
#o automate the tas( of calculating area of different shapes such as circle and rectangle&
%rchBuild contacts %B+ SoftDev rivate !imited& which is a software development
organisation" %rchBuild as(s %B+ SoftDev to create an application& which will allow the
architects wor(ing in %rchBuild to obtain the area of a shape" %B+ SoftDev first
performs re3uirement analysis to understand the re3uirements of the architects" %fter
re3uirement analysis& it starts developing an application using the inheritance feature of
+, programming language" Inheritance feature allows a class in +, to inherit the
properties and methods defined in another class besides having its own properties and
methods" Inheritance allows programmers to reuse the code of one application in another
application" #he %B+ SoftDev creates the following application for %rchBuild to
automate the tas( of calculating area for different shapes9
using System;
using System.Collections.Ieneric;
using System.'eGt;
namespace CaseStudy-6
{
public abstract class 1imensionJS5ape
{
protected string color8alue;
public 1imensionJS5ape(string color)
{
t5is.color8alue color;
.
public string getColor()
{
return color8alue;
.
public abstract double get%reao9JS5ape();

.
public class S5apeCircle * 1imensionJS5ape
{
private double radiuso9Circle;
public S5apeCircle(string color8alue, double radius)
* base(color8alue)
{
t5is.radiuso9Circle radius;
.
public override double get%reao9JS5ape()
{
return System.(at5.PI H radiuso9Circle H radiuso9Circle;
.
.
public class S5ape&ectangle * 1imensionJS5ape
{
private double lengt5o9&ectangle;
private double 3idt5o9&ectangle;
public S5ape&ectangle(string color8alue, double lengt5, double
3idt5)
* base(color8alue)
{
t5is.lengt5o9&ectangle lengt5;
t5is.3idt5o9&ectangle 3idt5;
.
public override double get%reao9JS5ape()
{
return lengt5o9&ectangle H 3idt5o9&ectangle;
.
.
public class S5apeSMuare * 1imensionJS5ape
{
private double lengt5o9SMuare;
public S5apeSMuare(string color8alue, double lengt5) *
base(color8alue)
{
t5is.lengt5o9SMuare lengt5;
.
public override double get%reao9JS5ape()
{
return lengt5o9SMuare H lengt5o9SMuare;
.
.

class %reaandColor
{
static void (ain(stringAB args)
{
Console.!rite"ine(#'5is is an eGample 35ere all t5e
properties o9 di99erent classes$nli0e Circle,SMuare can be de9ined in
anot5er class and can be in5erited $n9rom it 35en reMuired 3it5out
populating t5e classes 3it5 eGcess codes.#);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,#);
1imensionJS5ape myCircle ne3 S5apeCircle(#(aroon#, K);
1imensionJS5ape my&ectangle ne3 S5ape&ectangle(#2lue#,
-4, N);
1imensionJS5ape mySMuare ne3 S5apeSMuare(#Iray#, -/);
System.Console.!rite"ine(#'5e Circle is o9 # =
myCircle.getColor()
= # color and its area is # =
myCircle.get%reao9JS5ape() = #.#);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,#);
System.Console.!rite"ine(#'5e &ectangle is o9 # =
my&ectangle.getColor()
= # color and its area is # =
my&ectangle.get%reao9JS5ape() = #.#);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,#);
System.Console.!rite"ine(#'5e sMuare is o9 # =
mySMuare.getColor()
= # color and its area is # = mySMuare.get%reao9JS5ape()
= #.#);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,#);
.
.
.

#he use of inheritance in the application for calculating the area helps programmers avoid
defining e$cess code in one class" #he properties and methods defined in one class can be
easily used in another class because of inheritance
Chapter 15 Case Study
Problem Statement
4Info rivate !imited is involved in the development of new aircrafts for companies li(e
%ero.ly and .ly)igh" When developing the designs for the new aircrafts the designing
staff of 4Info has to do a number of comple$ calculations" /anually performing these
comple$ calculations has become tedious tas( for the designing staff of 4Info" )ow can
4Info automate the tas( of performing comple$ calculations*
Solution
#he management of 4Info after much discussion came to the conclusion that an
application must be developed to automate the tas( of performing comple$
calculations" .or this purpose& it contacts a software development company called
%B+ Software Solutions rivate !imited" #his software development company first
performs a re3uirement analysis to understand the re3uirements of 4Info" It then
decides that operator overloading feature of +, should be used in a +, application to
overload operators such as ? and @ so that different functions can be performed using
the same operator" %fter 51 days& the %B+ Software Solutions rivate !imited
comes up with the following +, application& which helps perform mathematical
operations such as adding and multiplying two numbers9
EEOperator Overloading using in5eritance
using System;
using System.Collections.Ieneric;
using System.'eGt;
namespace OperatorOverloading
{
class Store8alue
{
private int num-;
private int num4;
public Store8alue()
{
.
public Store8alue(int m, int n)
{
num- m=m;
num4 n=n;
.
public void 1isplay!indo3()
{
Console.!rite"ine(#'5e sum o9 numbers is {+. {-.#, num-,
num4);
.

.

class In5erit8alue * Store8alue
{
private double num- ;
private double num4 ;
public In5erit8alue(double a, double b)
{
num- aHa;
num4 bHb;
.
public In5erit8alue()
{
.
public ne3 void 1isplay!indo3()
{
Console.!rite"ine(#No3 t5e sMuare o9 t5e numbers 6// and F//
are {+. and {-.#,num-,num4);
.
.
class In5erit(ore8alue * In5erit8alue
{
private double num-;
private double num4;
public In5erit(ore8alue(double a, double b)
{
num- (a H b) E (a=b);
num4 (a H b) E (b,a);
.
public In5erit(ore8alue()
{
.
public ne3 void 1isplay!indo3()
{
Console.!rite"ine(#'5e value o9 t5e numbers F? and K4 are
{+. and {-.#, num-, num4);
.
.

class Program
{
static void (ain(stringAB args)
{
Console.!rite"ine(#Operator Overloading 3it5 In5eritance.#);
Store8alue ObD- ne3 Store8alue(--N,4?+);
ObD-.1isplay!indo3();
In5erit8alue ObD4 ne3 In5erit8alue(6//,F//);
ObD4.1isplay!indo3();
In5erit(ore8alue ObD6 ne3 In5erit(ore8alue(-/+,4/+);
ObD6.1isplay!indo3();

.
.
.
By the use of operator overloading in a +, application& a new definition for operators
such as ?& @ and ?? can be provided" Aperator overloading allows you to use
operators supported by +, to wor( with classes and structs in the same way as these
operators function with builtBin data types"
Chapter 17 Case Study
Problem Statement
/odern Engineering +ollage provides courses for streams such as mechanical& electrical&
electronics and civil" When a student ta(es admission in the /odern Engineering +ollage
and comes to the administrative staff to pay the fees& the staff has to manually fill a form
specifying details such as name& address& course and fees" % large amount of time is
consumed in the filling of the form" In addition& the efficiency of the administrative staff
also decreases as a lot of time is spent in filling of the form" #he students who are ta(ing
admission in the /odern Engineering +ollage have to wait for long time in a 3ueue for
paying their fees" )ow can /odern Engineering +ollage solve this problem of the
students and the administrative staff*

Solution
#he principal of /odern Engineering +ollage along with some of the important
management staff conducts a meeting and tries to find the solution to the problem& which
is being faced by the students ta(ing admission in the collage and the administrative staff"
By the end of the meeting& the principal and the management staff come to the conclusion
that an application must be developed for automating the tas( of entering student
information such as name and address" #he principal calls the )ead of the Electronics
department after a few days and as(s the )ead to develop the application" #he )ead of
the Electronics department first conducts a re3uirement analysis through interviews with
the administrative staff of the collage" %fter the analysis& the )ead of Electronics
Department comes to the conclusion that methods such as <ead!ineCD and Write!ineCD
available in +, must be used in a +, application for obtaining details such as name and
address and displaying a message to confirm the admission of the student" #he methods
such as <ead!ineCD and Write!ineCD help in receiving inputs from users and displaying
output" #he following +, application is developed by the )ead of the Electronics
department9
using System;
using System.Collections.Ieneric;
using System.'eGt;
namespace Student%dmissionSystem
{
public enum 1egree
{
(ec5anical -,
)lectrical,
)lectronics,
%eronautics,
Civil
.
class Select
{

public 1egree degree;

public Select()
{
degree 1egree.Civil;
.
public Select(1egree degree)
{

degree 1egree.Civil;
.

.
class Iet1etails
{
Select degree;
string name,address,telep5one,course,9ees;
public Iet1etails()
{
degree ne3 Select();
.
public void Iet%dmission()
{
int c5oice +;
Console.!rite"ine(#)nter t5e 1egree course to ta0e
admission in (odern )ngineering College * #);
Console.!rite"ine(#,,,,,,,,,,,,,,,,,,,,,,,,,,,#);
Console.!rite"ine(#-. (ec5anical#);
Console.!rite"ine(#4. )lectrical#);
Console.!rite"ine(#6. )lectronics#);
Console.!rite"ine(#F. %eronautics#);
Console.!rite"ine(#/. Civil#);
Console.!rite(#Please enter your C5oice* #);
c5oice int.Parse(Console.&ead"ine());
s3itc5 (c5oice)
{
case -*
degree.degree 1egree.(ec5anical;
brea0;
case 4*
degree.degree 1egree.)lectrical;
brea0;
case 6*
degree.degree 1egree.)lectronics;
brea0;
case F*
degree.degree 1egree.%eronautics;
brea0;
de9ault*
degree.degree 1egree.Civil;
brea0;

.
.
public void IetStudent1etails()
{
Console.!rite(#)nter name * #);
name Console.&ead"ine();
Console.!rite"ine(##);
Console.!rite(#)nter address * #);
address Console.&ead"ine();
Console.!rite"ine(##);
Console.!rite(#)nter telep5one * #);
telep5one Console.&ead"ine();
Console.!rite"ine(##);
Console.!rite"ine(##);
Console.!rite(#Course * # = degree.degree);
course degree.degree.'oString();
Console.!rite"ine(##);
Console.!rite(#)nter @ees * #);
9ees Console.&ead"ine();
.


class Student(enu
{
static void (ain(stringAB args)
{
Iet1etails gd ne3 Iet1etails();
gd.Iet%dmission();

Console.!rite"ine();
gd.IetStudent1etails();
Console.!rite"ine();
Console.!rite"ine(#'5an0 Cou # = gd.name = # 9or
getting %dmission in # = gd.course= # course.#);
.
.
.
.
In +,& methods such as <eadCD and WriteCD allow programmers to perform input and
output operations" #his means that these methods can be used to receive inputs such as
te$t and numbers from a user in a specific format and display the output in a particular
format"
Chapter 19 Case Study
Problem Statement
-ishant is wor(ing as a programmer for Best I# Solutions rivate company& which is
involved in developing high end software applications using technologies and
programming languages& such as %S"-E# and +," -ishant is as(ed by his ro'ect
/anager to create a server based application for B"/ Enterprises" #he server based
application has to run on a server for processing of specific data" #he ro'ect /anager
has as(ed -ishant to ta(e care that the load on the server must be minimum when the
application is run" What functionality should -ishant implement in his application to
decrease the load on server*
Solution
-ishant must implement the functionality of multithreading& which is supported in +,
programming language to decrease the load on the server" In multithreading& multiple
threads are run simultaneously during the e$ecution of a program or application" -ishant
first creates the following sample +, application to understand the concept of
multithreading9

using System;
using System.Collections.Ieneric;
using System.'eGt;
using System.'5reading;
namespace '5reading
{
class '5readed%pplications
{
static void (ain(stringAB args)
{
%pplicationCounter acObD ne3 %pplicationCounter();
'5readStart eGecute ne3
'5readStart(acObD.applicationJstopstart);
'5irdParty%pplications acObD4 ne3
'5irdParty%pplications();
'5readStart eGecute4 ne3
'5readStart(acObD4.t5irdapplicationJstopstart);
'5read applications ne3 '5read(eGecute);
Console.!rite"ine(#Starting t5e Primary %pplication.#);
'5read applications4 ne3 '5read(eGecute4);
EEstarting t5e primary application
applications.Start();
applications4.Start();
EEstarting t5e secondary applications

9or (int m -; m 7 /; m==)
{
Console.!rite"ine(#)Gecuting t5e Primary %pplication*
p{+.#, m);
'5read.Sleep(-+++);

.
Console.!rite"ine(#Primary %pplication ended#);
.
.
public class %pplicationCounter
{

public void applicationJstopstart()
{
Console.!rite"ine(#Starting Secondary %pplications no3.#);
9or (int m -; m 7 -+; m==)
{
Console.!rite"ine(#)Gecuting Secondary %pplication *
s{+.#, m);

'5read.Sleep(/++);
.
Console.!rite"ine(#Secondary %pplication ended#);
.
.
public class '5irdParty%pplications
{

public void t5irdapplicationJstopstart()
{
Console.!rite"ine(#Starting '5ird Party %pplications no3.#);
9or (int m -; m 7 -/; m==)
{
Console.!rite"ine(#)Gecuting '5ird Party %pplication *
t{+.#, m);
'5read.Sleep(4+++);
.
Console.!rite"ine(#'5ird Party %pplications ended#);
.
.
.
In +,& multithreading helps in optimising the resources related to a specific application" It
also helps in faster e$ecution of an application" /ultithreading can be used in +, to
create different threads for performing operations such as chec(ing the user input
and performing bac(ground tas(s"

You might also like