+ All Categories
Home > Documents > INTRO TO C++ COSSIPORE

INTRO TO C++ COSSIPORE

Date post: 26-Feb-2018
Category:
Upload: dheeraj-singh-jodha
View: 222 times
Download: 0 times
Share this document with a friend

of 31

Transcript
  • 7/25/2019 INTRO TO C++ COSSIPORE

    1/31

    KENDRIYA VIDYALAYA SANGATHAN, KOLKATA REGION

    Computer Science Question Bn!

    "nit # $

    "nit % C&pter VSA

    '( )r!*

    SA I

    '$

    )r!s*

    SA II

    '+ )r!s*

    LA

    ' )r!s*

    Tot-

    Object Oriented Programming in C++

    a) Introduction to OOP using C+

    +

    _ 1 _ 1 (2) 6

    b) Constructor& Destructor _ 1 _ _ (1) 2c) Inheritance - - - 1 (1) d) Pointers - - 1 - 1(!)e) Data "i#e $and#ing 1 1 1 - (!) 6

    Tot-

    I).ORTANT Q"ESTIONS '( OR $ TI)ES*C&pter # Intro/uction to OO. usin0 C11

    2%%

    Define the term Data Hiding in the context of Object Oriented Programming. Give aSuitable example using a C++ code to illustrate the same.

    2

    Define a class ravelPlan in C++ !ith the follo!ing descriptions "

    Private #embers"

    PlanCode of t$pe long

    Place of t$pe character arra$ %string&

    'umber(of(travellers of t$pe integer

    'umber(of(buses of t$pe integer

    Public #embers"

    ) constructor to assign initial values of Plan Code as **, Place as -)gra,

    'umber(of(travellers as /, 'umber(of(buses as *

    ) function 'e!Plan% & !hich allo!s user to enter PlanCode, Place and

    'umber(of(travellers. )lso, assign the value of 'umber(of(buses as per the

    follo!ing conditions "

    Number_of_travellersNumber_of_buses

    0ess than 1

    23ual to or more than 1 and less than 4

    23ual to 4 or more than 4 5

    ) function Sho!Plan% & to displa$ the content of all the data members on screen.

    2%%

    6

    De'ne u#ti#ee# and u#ti*#e inheritance in contet o, Object Oriented

    Programming .ie suitab#e eam*#e to i##ustrate the same

    2

  • 7/25/2019 INTRO TO C++ COSSIPORE

    2/31

    De'ne a c#ass named /DI00IO in C++ ith the ,o##oing descri*tions3

    Priate members3

    /D_O integer (4anges 1% - 2%%%)

    /5 /rra o, characters (0tring)

    C7/00 Character

    "550 "#oat

    Pub#ic embers3

    "unction 4ead_Data ( ) to read an object o, /DI00IO t*e

    "unction Dis*#a() to dis*#a the detai#s o, an object

    "unction Dra-os ( ) to choose 2 students random#

    /nd dis*#a the detai#s 8se random ,unction to generate admission nos to

    match ith

    /D_O

    (

    )

    2%%

    9:hat do ou understand - b6 Data 5nca*su#ation and Data ;$iding *e o, t*e string

    0ticer o, t*e string

    / member ,unction .et0ticer() to assign the ,o##oing a#ues ,or 0ticer as *er

    the gien ">*e3

    ">*e 0ticeregetarian .455Contains 5gg 577O:on-

    egetarian

    45D

    Pub#ic embers

    / ,unction .et"ood() to a##o user to enter a#ues ,or "oodCode="ood=">*e and

    ca## ,unction .et0ticer() to assign 0ticer / ,unction 0ho"ood() to a##o user to ie the content o, a## data members

    2%1

    !

    :rite an to diNerences beteen Constructor and Destructor :rite the ,unction

    headers ,or constructor and destructor o, a c#ass ember

    2

    De'ne a c#ass >ourist in C++ ith the ,o##oing s*eci'cation3

    Data embers

    carno Q to store us o

    Origin Q to store P#ace name

    Destination Q to store P#ace name

    >*e Q to store Car >*e such as R5S ,or 5conom

    Distance Q to store the Distance in ?i#ometers

    Charge Q to store the car ,are

    ember "unctions

    / contructor ,unction to initia#iTe >*e as R5S and "reight as 2%

    / ,unction Ca#cCharge() to ca#cu#ate "are as *er the ,o##oing citeria3>*e ChargeR5S 16 U DistanceR/S 22 U DistanceR7S !% U Distance

    / ,unction 5nter() to a#o user to enter a#ues ,or carno=origin=destination=t*e and

    distance /#so this ,unction shou#d ca## Ca#cCharge() to ca#cu#ate "are/ ,unction 0ho () to dis*#a the content o, a## the data members on screen

    2%1

    =rite an$ t!o differences bet!een Constructor and Destructor. =rite function headers for

    constructor and destructor of a class #ember.

    2

    %c& Define a class ourist in C++ !ith the follo!ing specification "Data #embers

    6 Camo > to store ?us 'o

    6 Origin > to store Place name

    6 Destination > to store Place name

    6 $pe > to store Car $pe such as @2@ for 2conom$

    6 Distance > to store the Distance in Ailometers

    6 Charge > to store the Car Bare #ember Bunctions

    6 ) constructor function to initialie $pe as @2@ and Breight as 1/

    6 ) function CalcCharge%& to calculate Bare as per the follo!ing criteria "

    $pe Charge

  • 7/25/2019 INTRO TO C++ COSSIPORE

    6/31

    @ 2 @ *EDistance

    @) @ 11EDistance

    @ 0 @ 5EDistance

    6 ) function 2nter%& to allo! user to enter values for Carno, Origin, Destination, $pe and

    Distance. )lso, this function should call CalcCharge%& to calculate Bare.

    6 ) function Sho!%& to displa$ the content of all the data members on screen.

    C&pter 2 Constructor 3 Destructor2%%

    )ns!er the 3uestions %i& and %ii& after going through the follo!ing class"

    class Test

    {

    char Paper[20];

    int Marks;

    public:

    Test () // Function 1

    {

    strcpy (Paper, Computer)

    Marks = 0;

    }

    Test (char P [] ) // Function 2

    {

    strcpy(Paper,P);

    Marks = 0;

    }

    Test (int M) // Function 3

    {

    strcpy(Paper,Computer);

    Marks = M;

    }

    Test (char P[], int M) // Function 4

    {

    strcpy (Paper, P);

    Marks = M;

    }

    };

    %i& =hich feature of Object Oriented Programming is demonstrated using

    Bunction *, Bunction 1, Bunction 5 and Bunction 4 in the above class estF

    %ii& =rite statements in C++ that !ould execute Bunction 1 and Bunction 4 of

    class est.

    2

    2%%

    6/nser the Muestions (i) and (ii) a,ter going through the ,o##oing c#ass3

    c#ass Interie

    V int monthW

    *ub#ic3

    Interie (int ) VmonthG WX YYConstructor 1

    Interie (Interie&t)W YYConstructor 2

    XW

    i Create an object= such that it inoes Constructor 1

    2

  • 7/25/2019 INTRO TO C++ COSSIPORE

    7/31

    ii :rite com*#ete de'nition ,or Constructor 2

    2%%

    9

    Answer the questions (i) and (ii) after going through the following

    class "class Exam

    int Rno,MaxMarks,MinMarks,Marks;

    public:

    Exam () I /Module 1Rno=l01;MaxMarks=l O O;MinMarks=0;Marks=!";

    Exam (int #rno,int #marks) I /Module $

    Rno=#rno;MaxMarks=lO O;MinMarks=0;Marks=#marks;%Exam () I /Module &

    cout'' ** Exam Oer ** ''endl;

    oid *o+ () I /Module

    cout''Rno'' :''MaxMarks'' :''MinMarks''endl;cout''

    -Marks .ot ''Marks''endl;

    G ;

    (i) As per Obect Oriented !rogramming" which concept is

    illustrated b# $odule % and $odule & together F

    (ii) 'hat is $odule referred as F 'hen do #ou think")o/u-e + 4i-- 5e in6o!e/%c--e/ rae#(Boat C) YY "unction 2

    V

    CoutFFP#aceCodeFF]3]FFP#aceFF]3]FFChargesFFend#WX

    `>rae#() YY "unction !

    V

    CoutFF]>rae# P#an Cance##ed]FFend#W

    X

    >rae#(intPC=char PZ[=Boat C) YY "unction

    V

    P#aceCode G PCW strc*(P#ace=P)W Charges G CW

    X XWi) In Object Oriented Programming= hat are "unction 1 and "unction

    combined together re,erred as #otor '%# &K Option 1 > #otor P%lO &K(ii) ame the ,eature o, Object Oriented Programming= hich is i##ustrated b

    "unction 1= "unction 2 and "unction ! combined together

    2

    C&pter 2 In&eritnce2%%

    )ns!er the 3uestions %i& to %iv& based on the follo!ing code" 4

    class Medicines

    {

    char Category[lO];

    char Date_of_manufacture[lO];

    char Company[20];public:

    Medicines();

    void entermedicinedetails();

    void showmedicinedetails();

    } ;

    class Capsules: public Medicines

    {

    protected:

    char capsule_name[30];

    char Volume_label[20];public:

    float Price;

    Capsules();

    void entercapsuledetails();

    void showcapsuledetails();

    };

    class Antibiotics: public Capsule

    {

    intDosage_units;

  • 7/25/2019 INTRO TO C++ COSSIPORE

    12/31

    char Side_effects[20];

    intUse_within_days;

    public:

    Antibiotics() ;

    void enterdetails();

    void showdetails();

    };

    %i& Ho! man$ b$tes !ill be re3uired b$ an object of class #edicines and an object

    of class )ntibiotics respectivel$F%ii& =rite names of all the member functions accessible from the object of class

    )ntibiotics.

    %iii& =rite names of all the members accessible from member functions of class

    Capsules.

    %iv& =rite names of all the data members, !hich are accessible from objects of class

    )ntibiotics.2%%

    6/nser the Muestions (i) to (iii) based on the ,o##oing code

    c#ass stationar

    V

    char >*eWchar anu,acturer Z1%[W

    *ub#ic3

    stationar()W

    oid 4ead_sta_detai#s( )W

    oid Dis*_sta_detai#s( )W

    XW

    c#ass oce3 *ub#ic stationar

    V

    intno_o,_t*esWBoat cost_o,_staW

    *ub#ic3

    oid 4ead_oN_detai#s( )W

    oid Dis*_oN_detai#s( )W

    XW

    c#ass *rinter3 *riate oce

    V

    intno_o,_usersW

    char de#ier_dateZ1%[W

    *ub#ic3

    oid 4ead_*ri_detai#s( )W

    oid Dis*_*ri_detai#s( )W

    XW

    oid main ( )

    V *rinter PrinterW X

    i ention the member names hich are accessib#e b Printer dec#ared in

    main() ,unction

    ii :hat is the siTe o, Printer in btesCodeW

    char >ame Z2%[W *rotected3

    Boat 0a#arW *ub#ic3

    >eacher()W oid 5nter ()W oid 0ho ()W

    XW

    c#ass Course3 *ub#ic 0tudent = *riate >eacher

    V

    #ong CCodeZ#O[Wchar CourseameZ 0O[W char 0tartDateZJ[=5ndDateZJ[W*ub#ic3

    Course( )W

    oid Commence ()W oid CDetai# ()W

    X W

    (i) :rite the names o, member ,unctions= hich are accessib#e ,rom objects o, c#ass

    Course

    (ii) :rite the names o, a## the data members= hich isYare accessib#e ,rom member

    ,unction Commence o, c#ass Course

    (iii) :rite the names o, a## the members= hich are accessib#e ,rom objects o, c#ass

    >eacher

    (i) :hich t*e o, Inheritance 1s i##ustrated in the aboe C++ code eacher()W

    oid 5nter()W

    oid sho()W

  • 7/25/2019 INTRO TO C++ COSSIPORE

    17/31

    XW

    C#ass Course 3 *ub#ic 0tudent = *riate >eacher

    V

    7ong CCodeZ1%[W char CourseameZ&%[W

    Char 0tartDateZJ[=5ndDateZJ[W

    Pub#ic3

    Course()W

    oid Commerce()Woid CDetai#s()W

    XW

    (i) :rite the names o, member ,unctions= hich are accessib#e

    ,rom objects o, c#ass Course-

    %ii&=rite the names of all the data members, !hich isRare accessible from

    member function Commence of class Course.%iii&=rite the names of all .the members, !hich are accessiblefrom objects ofclass eacher.%iv&=hich t$pe of ;nheritance *s illustrated in the above C++ code F

    2%1

    2

    /nser the Muestions (i) to (i) based on the ,o##oing 3

    c#ass COP/

    char 7oca tion Z2% [ W

    doub#e udget = IncorneW *r otected 3

    oid /ccou n ts ( ) W *ub#ic 3

    COP/ ( ) W

    oid 4egister ( ) W oid 0ho ( ) W

    X W

    c#a ss "/C>O4 3*ub#ic COP/

    char 7ocation ( 2 % ) W int :or ersW*rotected 3

    doub#e 0a#ar W oid Com*uter ( ) W

    *ub#ic 3

    "/C>O4 () W

    oid 5nter ( ) W oid0ho ( ) W

    X W

    c#ass 0$OP 3 *r iate COP/

    cha r 7oca t ion Z 2 % [ W , #oat /rea Wdoub#e 0a#e W *ub#ic 3

    0$OP ( ) W

    oid In*u t ( ) W oid Out*u t ( ) W

    X W

    %i& 'ame the t$pe of inheritance illustrated m the above C++code.

    %ii& =rite the name of data members, !hich arc accessible frommember

    functions of class SHOP.

    %iii& =rite the names of all the member fonction s, !hich areaccessible

  • 7/25/2019 INTRO TO C++ COSSIPORE

    18/31

    from objects belonging to class B)CO7ota#= /gW

    Pub#ic3

    Char Oera##.rade=4emarsZ2%[W4e*ort()W

    oid 4ea#uate()W

    oid 4Print()W

    X W

    (i) :hich t*e o, Inheritance is shon in the aboe eam*#e ota#= /gW *ub#ic3

    char Oera##.rade= 4emars Z2%[W

    4e*ort()W

    oid 45a#uate( )W oid 4Print()W

    X i

    (i) :hich t*e o, Inheritance is shon in the aboe eam*#e et Z[G/*5/CeDri 5 W Code(>et= LL )W

    coutFF 5: >5>3 FF>etFFend#W

  • 7/25/2019 INTRO TO C++ COSSIPORE

    22/31

    2%1

    1Bind the output of the follo!ing program "

    \inc#ude FiostreamhH oid main ()

    V

    int Uueen=oesZ [GV##=22=!!=XW ueenGoesW

    oesZ 2[+G22W

    coutFFueen FFUueenFFend#W

    Uueen-G11W ueen+G2W

    coutFFo FFUueenFF nd#W ueen++WcoutFF"ina## FFUueenFFend#W

    coutFFe Origin FFoesZO[FFend#W

    2%1

    2Bind the output of the follo!ing program

    include 'iostrearn *2

    include 'ct3pe *2

    t3pede4 c*ar tr50 4 50;

    void main%&

    N c*ar 67otes;

    tr50 8r9%R$.ooO ;

    int 8=;7otes=tr

    ;+*ile (82=& )

    tr -8= (isupper (tr>;

    G2%1

    Obsere the ,o##oing C++ code care,u## and obtain the out*ut= hich i## a**ear on

    the screen a,ter eecution o, it

    Im*ortant ote 3

    /## the desired header '#es are a#read inc#uded in the code= hich are reMuired to run

    the code

    oid main ( )

    V

    char U0tringG0$/?>I W

    int UPoint=a#ueZ[GV#%=1=9%=1KXW PointGa#ue W coutccUPointcc0tringccend#W 0tring+

    +W

    Point++ W coutccUPointcc0tringccend# W

    X

  • 7/25/2019 INTRO TO C++ COSSIPORE

    23/31

    C&pter #Dt 9i-e Hn/-in02%%

    6oid main( )

    V charGS/SW

    ,stream '#eout(]datadat]=ios33out)W '#eoutFFchW

    int * G '#eoutte##g( )W coutFF*W

    X

    :hat is the out*ut i, the '#e content be,ore the eecution o, the *rogram is the

    string ^/C] (ote that] ^are not *art o, the '#e):rite a ,unction to count the number o, ords *resent in a tet '#e named ^P/4/>>]

    /ssume that each ord is se*arated b a sing#e b#anYs*ace character and no

    b#ansYs*aces in the beginning and end o, the '#ec "o##oing is the structure o, each record in a data '#e named CO7OD/>]

    structCO7O

    N char Colon$

    CodeL*MK

    char Colon$'ameL*MK int

    'o of PeopleKK=rite a function in C++ to update the file !ith a ne! value of 'o (of(People.he value of Colon$(Code and 'o(of(People are read during the execution ofthe program.

    2%%

    9Obsere the *rogram segment gien be#o care,u##6 and '## the

    b#ans mared as 0tatement 1 and 0tatement 2 using te##g() and

    see*() ,unctions ,or *er,orming the reMuired tas-

    \inc#ude F,streamhHc#ass Customer

    V lon? @no;c*ar 7ame-$0, Mobile-1$;public:

    //Aunction to allo+ user to enter t*e @no, 7ame, Mobile

    oid Enter();

    //Aunction to allo+ user to enter (modi43) mobile number

    oid Modi43();

    //Anction to return alue o4 @nolon?

    .et@no() Breturn @no;C

    C;

    void Change#obile%&

    N

    Customer CK

    fstream BK

    B.open %** CO')C. D) ** , i.os" "binar$ ; ios" "in ; ios"out&

    K

  • 7/25/2019 INTRO TO C++ COSSIPORE

    24/31

    long CnocK RRCustomer no. !hose mobile number needs to be

    c"KhanC,ed6. cin99CnocK

    !hile %B.read%%charE&C,sieof%C&&&

    if %Cnoc::C.GetCno%&&

    C.#odif$ %&K

    RRStatement *

    int Pos:; Ro fin3 the curret position of file pointer V@K6

    RRStatement 1

    RRo move the file pointer to !rite the .

    RRmodified record bac8 onto the file

    RRfor the des.ired Cnoc 6 B.!rite% %charE&C,sieof%C&&K

    @

    B.close%&K2%%

    J

    Observe the program segment given belo! carefull$ and fill the blan8s mar8ed as Statement

    * and Statement 1 using see8g% &, see8p% &, tellp% & and tellg% & functions for performing there3uired tas8.

    \ inc#ude F,stream-hH

    class P7ODC

    {

    int Pno Kchar Pname L1M K int Wt$ K

    public "

    void #odif$Wt$ % &II he function is to modif$ 3uantit$ of a P7ODC

    K

    void P7ODC " " #odif$Wt$ % &

    {

    fstream Bile K

    Bil.open %JP7ODC.D)J, ios " " binar$ I ios " " in I ios " " out& Kint #PnoK

    cout II JProduct 'o to modif$ 3uantit$ "J Kcin99 #Pno K

    !hile %Bil.read %%charE& this, sieof %P7ODC& & &

    N

    if %#Pno: :Pno&

    {coutII JPresent Wuantit$"J IIWt$IIendl KcoutII JChanged

    Wuantit$"J Kcin99Wt$ K

    int Position : RRStatement *

    RRStatement 1

    Bil.!rite % %charE& this, sieof %P7ODC& & K I I 7e>!riting therecord

    G

  • 7/25/2019 INTRO TO C++ COSSIPORE

    25/31

    Bil.cBil.close% & K

    }

    =rite a function in C++ to count the no. of J#eJ or J#$J !ords presenttext file JD;)75D/>]=ios33binar f ios33in f ios33out)WInt CInoW

    CoutFF]Item o to modi, *rice 3]W cinHHCinoW

    :hi#e("i#eread((char U)this=siTeo,(I>5))

    V

    I,(Cino GG Ino)

    V

    CoutFF]Present Price3 ]FFPriceFFend#W

    CoutFF]Changed Price3]W cinHHPriceW

    Int "i#ePos G ___________W YY statement 1

    _____________________W 0tatement 2

  • 7/25/2019 INTRO TO C++ COSSIPORE

    26/31

    "i#erite ((char U) this= siTeo,(I>5))W YY 4e-riting the record

    X

    X

    "i#ec#ose()W

    =rite a function in C++ to count the no. of -He or -She !ords present in a text file

    -SO7he user shou#d enter the ode# o and the,unction shou#d search and

    dis*#a6 the detai#s o, the camera-

    C#ass C/54/

    V

    7ong ode#oW

    "#oat egaPie#W

    Int oomW

    Char Detai#sZ12%[W

    Pub#ic3

    oid 5nter() VcinHHode#oHHegaPie#HHoomW gets(Detai#s)WX

    oid Dis*#a() V

    CoutFFode#oFFegaPie#FFoomFFDetai#sFFend#WX

    7ong .5tode#o() V return ode#oWX

    K

    2%1%

    Obsere the *rogram segment gien be#o care,u##6 and '## theb#ans mared as 0tatement 1 and 0tatement 2 using te##g() and

    see*() ,unctions ,or *er,orming the reMuired tas-

    include '4stream*2class

    @ustomer

    lon? @no;c*ar 7ame-$0, Mobile-1$;public://Aunction to allo+ user to enter t*e @no, 7ame, Mobile

    oid Enter();

    //Aunction to allo+ user to enter (modi43) mobile numberoid Modi43();

    //Anction to return alue o4 @nolon?

    .et@no() Breturn @no;C

    C;

    oid @*an?eMobile()

    {

  • 7/25/2019 INTRO TO C++ COSSIPORE

    27/31

    @ustomer @;

    4stream A;

    Aopen (**@O75

    V

    Int InoW

    Char InameZ2%[W Boat PriceW

    Pub#ic3

    oid odi,Price()W YY >he ,unction is to modi, *rice o, a *articu#ar I>5

    X3

    oid I>5 33 odi,Price()

    V

    "stream "i#eW

    "i#eO*en(^I>5D/>]=ios33binar f ios33in f ios33out)W

    Int CInoW

    CoutFF]Item o to modi, *rice 3]W cinHHCinoW

    :hi#e("i#eread((char U)this=siTeo,(I>5))

    V

    >>>

    *

  • 7/25/2019 INTRO TO C++ COSSIPORE

    28/31

    I,(Cino GG Ino)

    V

    CoutFF]Present Price3 ]FFPriceFFend#W

    CoutFF]Changed Price3]W cinHHPriceW

    Int "i#ePos G ___________W YY statement 1

    _____________________W 0tatement 2

    "i#erite ((char U) this= siTeo,(I>5))W YY 4e-riting the record

    XX

    "i#ec#ose()W

    X

    =rite a function in C++ to count the no. of JHeJ or JSheJ !ords present in atext file JSO7: WK

    void Purchase%int W& NWt$ + : WK

    int Getino%& N return ;noK

  • 7/25/2019 INTRO TO C++ COSSIPORE

    29/31

    K

    oid Purchae;tem%int Pino, int PWt$&

    N

    f stream Bi le K

    Bile .open % J SOCA .D) J , ios " "binar$ l ios " "in l ios " "@ou t & K Stoc8 S K

    ;nt Su ccess: O K

    !hile % Success:: O S S Bi le . read % % cha.r E& S S, siCeof % S& & &

    if % Pino::S .Get ;no %& &

    S .Purchase % PWt$& K

    ((((((((((((((((( RR Statement *

    ((((((((((((((((( R R Statement 1

    Success++K

    if% Su ccess:: l coutII JPu rcha se pdated J I Iendl K else

    coutII J= rong ;tem 'oJ IIendl K Bi le . close % & K

    (i) =rite statement * to position the file pointer to the appropriate

    place, so that the data updation is done for there3uired item.

    %ii&=rite statement 1 to perform the !rite operation so thatthe updation is

    done in the binar$ file.

    =rite a function in C++ to read the content of a text fileJD20H;.XJ and displa$ all those lines on screen, !hich areeither

    starting !ith @D@ or starting !ith @#@.

    =rite a function in C++ to search for the details %Phoneno and calls& of those Phones,

    !hich have more than Y calls from a binar$ file -Phones.dat. )ssuming that this

    binar$ file contains records objects of class Phone, !hich is defined belo! .

    Class Phone

    N

    c*ar #*oneno-lO;int @alls;

    public :

    oid .et ()B?ets(#*oneno); cin22@alls;C

    oid Lillin?()Bcout''#*oneno''''@al ls''endl;C

    int .et@alls ()Breturn @alls;C

    K2%1

    Bill in the blan8s mar8ed as Statement * and Statement 1, in the program segment givenbelo! !ith appropriate functions for the re3uired tas8.

  • 7/25/2019 INTRO TO C++ COSSIPORE

    30/31

    class @ustomer

    N

    long int C'oK RR Customer 'umber

    char C'mae L1+MK RR customer 'ame

    char 2mailL5+MK RR 2mail of customer

    public"

    void )llocate%&K RR Bunction to allocate a member

    void sho!%&K RR Bunction to sho! customer data

    void #odif$2mail%& RR Bunction to modif$ 2mail

    N coutII..2nter #odified 2mail ".K

    Gets%2mail&K

    long int GetCno%& Nreturn C'oK

    K

    void ChangeData%&

    N

    fstream BileK

    Bile .open %** CS.D) ** , ios" "binar$ ; ios""in ; ios""out& K int Change:O ,0ocationK

    long int ChangeCnoK

    coutIIJCno > !hose email re3uired to be modified"JK cin99ChangeCnoK

    Customer CK

    !hile%Z#odif$ Bile.read%%charE&C,sieof %C&&&

    N

    if %C.GetCno%&::ChangeCno&

    N

    C .#odif$2mail%& K 0ocation:Bile.tellg%&> sieof %C&K

    RRStatement l "o place file pointer to the re3uired position

    RRStatement 1"o !rite the object C on to the binar$ file

    Change++K

    if %Change&

    coutI IJ2mail #odified ... ** IIendlK else

    coutII JCustomer not found ... ** IIendlK Bile .close%&K

    =rite a function CountHisHer % & in C++ !hich reads the contents of a text file

    diar#*t+t and counts the !ords His and Her %not case sensitive&.Bor example, if the file contains "

    #inak3 *as ?one to *is 4riend9s *ouse Kis 4riend9s

    name is Ra3a Ker *ouse is 1$ M 4rom *ere

    he function should displa$ the output as

  • 7/25/2019 INTRO TO C++ COSSIPORE

    31/31

    @ount 4or Kis:$

    @ount 4or Ker:l

    )ssuming the class ;')G2 as declared belo!, !rite a function in C++ to read the objects of

    ;')G2 from binar$ file ;')G2.D) an. d displa$

    those vintage vehicles, !hich are priced bet!een 1 and 1/.

    class ;')G2

    N

    int 'OK RRehicle 'umber

    char DescLlOM K RRehicle Description float PriceK

    .public "

    void G2%& Nc.in99'OKgets NDesc& Kcin99PriceK void ;2= N&

    N

    coutII'OIIendl K coutIIDescIIendlK coutIIPriceIIendl K

    float 7eturnPrice N& NreturnPriceK

    K


Recommended