laboratory 6

13
Laboratory 6 1) /*Write a C++ application that implements a class called F1Pilot. The class defines the private variables name (array of characters), team (array of characters), age (int), best_time (int) and pole_position_nr. As public members, the class contains mutator and accessor methods for each of the class’s attributes. In function main, create 3 different instances of the F1Pilot class and use the mutator methods for initializing each object’s data with the corresponding information read from the keyboard. Using the accessor methods, display all the data related to the pilot that has the best time.*/ #include<stdio.h> #include<stdlib.h> #include<string.h> class PilotF1 { char *nume; char *echipa; int varsta; int record; int nr_pole_position; public: PilotF1() {} PilotF1(PilotF1& pilot); void write_nume(char n[]); void write_echipa(char e[]); void write_varsta(int v); void write_record(int r); void write_nr_pole_position(int p); const char *get_nume(); const char *get_echipa(); int get_varsta(); int get_record(); int get_nr_pole_position(); }; void Afisare(PilotF1 *pilot); int main(void) {

Upload: covalschi-ionut

Post on 17-Dec-2015

1 views

Category:

Documents


0 download

DESCRIPTION

laborator programare

TRANSCRIPT

Laboratory 6

1) /*Write a C++ application that implements a class called F1Pilot. The class defines the privatevariables name (array of characters), team (array of characters), age (int), best_time (int) andpole_position_nr. As public members, the class contains mutator and accessor methods foreach of the classs attributes.In function main, create 3 different instances of the F1Pilot class and use the mutator methodsfor initializing each objects data with the corresponding information read from the keyboard.Using the accessor methods, display all the data related to the pilot that has the best time.*/

#include#include#includeclass PilotF1{char *nume;char *echipa;int varsta;int record;int nr_pole_position;public:PilotF1() {}PilotF1(PilotF1& pilot);void write_nume(char n[]);void write_echipa(char e[]);void write_varsta(int v);void write_record(int r);void write_nr_pole_position(int p);const char *get_nume();const char *get_echipa();int get_varsta();int get_record();int get_nr_pole_position();};void Afisare(PilotF1 *pilot);int main(void){int nr_piloti,best[2]={0,0};//best[0] reprezinta valoarea recordului mare, best[1] reprezinta i-ul pilotului;char bufc[256];int bufi;printf("Introduceti cati piloti doriti sa introduceti:");scanf("%d",&nr_piloti);PilotF1 *p=new PilotF1[nr_piloti];for(int i=0;iget_varsta(),pilot->get_nr_pole_position(),pilot->get_record());

}

2) /*Modify the 2-nd example so that the code could be launched into execution*/

#include using namespace std;class Test2{int x;public:Test2(){coutdim2;cout