Sie sind auf Seite 1von 4

Lab3

Class
NAME
:__________________________________________
Objective:
Aftercompletionofthislab,youwillbeableto
defineanduseyourownC++classes.

LabExercise
1.Writeaprogramnamed
lab3_1.cpp
thatcontainsaclassnamed
Temperature
tostore
temperatureinformation.Informationthatwillberelevanttostoreis
degree
and
scale.
(1)Defineamemberfunctionnamed
set()
,whichallowsyoutosetallmembervariables.This
functionhasanemptyparameterlist,anditsreturntypeisvoid.
(2)Defineamemberfunctionnamed
print()
thatprintsasummaryoftheTemperatureobject.
Youcanchoosehowthisdataisformattedtothescreen(somethingreadableplease).

Testyourclasswiththedriverprogramgivenbelow.Ifyoufindanyproblemswiththedriver
program,fixthem.

//SampleTestdriverforclassTemperature

#include<iostream>
usingnamespacestd

intmain()
{
Temperaturefirst,second,third

cout<<Pleaseentertemperatures:
first.set()
second.set()
third.set()

cout<<==========================\n
cout<<\tTemperatureList\n
first.print()
second.print()
third.print()

return0
}

CSS2A

Page1of4
SP16


Lab3

2.Writeaprogramnamed
lab3_2.cpp
thatcontainsaclassnamed
Student
tostorestudent
information.Informationthatwillberelevanttostoreis
name
,
idnumber
,
GPA,
and
major.
(1)Defineamemberfunctionnamed
set()
,whichallowsyoutosetallmembervariables.This
functionhasanemptyparameterlist,anditsreturntypeisvoid.So,withinthefunctionyoull
promptforinformation.
(2)Defineamemberfunctionnamed
print()
thatprintsasummaryoftheStudentobject.You
canchoosehowthisdataisformattedtothescreen(somethingreadableplease).
(3)Createadriverfiletotestyourclass.Youshouldinstantiateatleast3objectsofStudent
type.

Student

name:string
id:int
gpa:double
string:major

+ set():void
+ print():void

SampleRun(Userinputinbold):

StudentInformationDatabase
===============================
Name:
ElaineBenes
ID:
1961
GPA:
4.0
Major:
FrenchLiterature
Name:
GeorgeCostanza
ID:
1959
GPA:
2.7
Major:
Architecture
Name:
CosmoKramer
ID:
1949
GPA:
3.5
Major:
Business
=========Summary===========
ElaineBenes

(1961)

graduatedwitha4.0GPAinFrench
Literature.
GeorgeCostanza

(1959)

graduatedwitha2.7GPAinArchitecture.
CosmoKramer

(1949)

graduatedwitha3.5GPAinBusiness.

CSS2A

Page2of4
SP16


Lab3

3.Writeaprogramnamed
lab3_3.cpp
thatcontainsaclassnamed
Automobile
tostore
automobileinformation.Informationthatwillberelevanttostore
make
,
model,year,
and
mileage.

(1)Defineamemberfunctionnamed
set()
,whichallowsyoutosetallmembervariables.This
functionwillhaveaparameterlist(stringmake,stringmodel,intyear,intmileage),andits
returntypeisvoid.So,withinthefunctionyoullwonthaveanyinputstatements.Thesewill
bedoneinthe
main()
.
(2)Defineamemberfunctionnamed
print()
thatprintsasummaryoftheAutomobileobject.
Youcanchoosehowthisdataisformattedtothescreen(somethingreadableplease).
(3)Createadriverfiletotestyourclass.Youshouldinstantiateatleast3objectsof
Automobiletype.

Automobile

make:string
model:string
year:int
mileage:int

+ set(string,string,int,int):void
+ print():void

SampleRun(Userinputinbold):

AutomobileInformationDatabase
===============================
Make:
InternationalHarvester
Model:
ScoutII
Year:
1979
Mileage:
220000
Make:
LandRover
Model:
90
Year:
1984
Mileage:
150000
Make:
DeLorean
Model:
DMC12
Year:
1982
Mileage:
88000
=========Summary===========
1979InternationalHarvesterScoutIIwith220000miles.
1984LandRover90with150000miles.
1982DeLoreanDMC12with88000miles.

CSS2A

Page3of4
SP16


Lab3

Whenyoufinishyourlab,
submityourC++program,
lab3_1.cpp,Temperature.cpp,
Temperature.h,lab3_2.cpp,Student.cpp,Student.h,lab3_3.cpp,
Automobile.cpp
,and
Automobile.h
toetudes
.

CSS2A

Page4of4
SP16

Das könnte Ihnen auch gefallen