Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ООП звіт.doc
Скачиваний:
14
Добавлен:
23.03.2015
Размер:
101.38 Кб
Скачать

Виконання лабораторної роботи

  1. Виконав завдання з часин I, II:

//Book.h

#pragma once

#endif // _MSC_VER > 1000

class CBook

{

private:

char m_author [ 50 ] ;

char *m_pTitle ;

int m_year ;

public:

CBook ();

virtual ~ CBook ();

void setAuthor ( const char* ) ;

void setTitle ( const char* ) ;

void setYear ( const int ) ;

char* getAuthor ( void ) ;

char* getTitle ( void ) ;

int getYear ( void ) ;

} ;

//Book.cpp

#include "Book.h"

#include "iostream.h"

#include <string>

using namespace std;

// установить автора

void CBook :: setAuthor ( const char* author )

{ cout << "\n rabotaet setAuthor \n"<< author<< endl;

m_author [ 0 ] = '\0' ;

strcat(m_author, author);

cout << m_author<<endl;

cout << "\notrabotal setAuthor\n"<<endl;

}

// установить название

void CBook :: setTitle ( const char* title )

{

cout << "\nrabotaet setTitle\n"<<endl;

cout << "\nstrlen ( title ) = "<<strlen ( title )<<endl;

cout << "\ntitle = "<< title <<endl;

m_pTitle = new char [strlen ( title )+ 1] ;

m_pTitle [ 0 ] = '\0' ;

strcat(m_pTitle, title);

cout << m_pTitle<<endl;

cout << "\notrabotal setTitle\n"<<endl;

}

// установить год издания

void CBook :: setYear ( const int year )

{ m_year = year ; }

// вернуть автора

char* CBook :: getAuthor ( void )

{ return m_author ; }

// вернуть название

char* CBook :: getTitle ( void )

{ return m_pTitle ; }

// вернуть год издания

int CBook :: getYear ( void )

{ return m_year ; }

// конструктор по умолчанию

CBook :: CBook ( ) : m_year ( 0 ), m_pTitle ( " " )

{ m_author [ 0 ] = '\0' ;

cout << "default CONSTRUCTOR\nthis = " << this ;

}

// деструктор

CBook::~CBook()

{

delete [ ] m_pTitle ;

cout << "DESTRUCTOR\t " << this << endl ;

}

//Lab5_1

#include "stdafx.h"

#include <iostream>

using namespace std ;

#include "Book.h"

void view ( char*, CBook& ) ;

int main(int argc, char* argv[])

{

cout << "\n rabotaet Lab5_6.cpp " << endl;

CBook book;

CBook* book1 = new CBook;

char stroka_vvoda[10];

cout << "Vvedi avtora" << endl;

cin >> stroka_vvoda;

book.setAuthor ( stroka_vvoda ) ;

// book.setAuthor ( "Robert Lafore" ) ;

cout << "\n otrabotal setAuthor pole = " << book.getAuthor() << endl;

book.setTitle ( "Object-Oriented Programming in C++" ) ;

cout << "\n otrabotal setTitle pole = " << book.getTitle() << endl;

book.setYear ( 2004 ) ;

view ( "book", book ) ;

cout << "\n otrabotal view " << endl;

book1->setAuthor ("N.Gogol");

cout<<"\n otrabotal setAuthor pole = "<<book1->getAuthor() << endl;

book1->setTitle ( "Viy" ) ;

cout << "\n otrabotal setTitle pole = " << book1->getTitle() << endl;

book1->setYear ( 1835 ) ;

view ( "book1", *book1 ) ;

cout << "\n otrabotal view " << endl;

return 0;

}

void view ( char *s, CBook &o )

{

cout << "\nState of object \' " << s << " \'\n" ;

cout << "Author:\t" << o.getAuthor ( ) << endl ;

cout << "Title:\t" << o.getTitle ( ) << endl ;

cout << "Year:\t" << o.getYear ( ) << endl << endl ;

}

  1. Виконав завдання з частини III:

//Football.h

#pragma once

class Football

{

private:

char l_name[20];

int q_match;

int number;

public:

Football();

~Football();

void setLName( char* );

void setQ_match( int );

void setNumber( int );

void writeclass( char*, int, int );

};

//Football.cpp

#include "Football.h"

#include <iostream>

#include <string>

using namespace std;

void Football::setLName( char* lname )

{

l_name[0] = '\0';

strcat(l_name, lname);

}

void Football::setNumber( int mnumber )

{

number=mnumber;

}

void Football::setQ_match( int quantity )

{

q_match=quantity;

}

void Football::writeclass( char* laname, int mnumber, int quantity)

{

cout<<endl<<"Класс:"<<endl;

cout<<"Фамилия футболиста: "<<laname<<endl;

cout<<"Номер футболиста: "<<mnumber<<endl;

cout<<"Количество матчей футболиста: " <<quantity<<endl;

}

Football::Football() : number( 0 ), q_match( 0 )

{

l_name[0] = '\0';

}

Football::~Football( void )

{

delete [] l_name;

}

//Lab5_3.cpp

#include "iostream"

#include "conio.h"

#include "Football.h"

#include <math.h>

#include <stdlib.h>

using namespace std;

int main()

{

setlocale(LC_ALL,"Russian");

Football foot;

Football *footballer = new Football;

int mnumber, quantity;

char lname[20];

cout<<"----------------------------CHEREZ IMYA-----------------------";

cout<<endl<<"Введите фамилию футболиста: ";

cin>>lname;

foot.setLName(lname);

cout<<"Введите номер футболиста: ";

cin>>mnumber;

foot.setNumber(mnumber);

cout<<"Введите количество матчей футболиста: ";

cin>>quantity;

foot.setQ_match(quantity);

foot.writeclass( lname, mnumber, quantity);

system( "pause" );

system( "cls" );

cout<<"-------------------------CHEREZ UKAZATEL'-------------------";

cout<<endl<<"Введите фамилию футболиста: ";

cin>>lname;

footballer->setLName(lname);

cout<<"Введите номер футболиста: ";

cin>>mnumber;

footballer->setNumber(mnumber);

cout<<"Введите количество матчей футболиста: ";

cin>>quantity;

footballer->setQ_match(quantity);

footballer->writeclass( lname, mnumber, quantity);

system( "pause" );

return 0;

}

Висновок: Я спроектував, відлагодив та протестував розроблені функції-члени класу, використав розроблені методи для роботи з об’єктами класу.