• Nie Znaleziono Wyników

Wykład 1Wprowadzenie do projektowania i programowania obiektowej aplikacji w środowisku typu CASE1.Projekt aplikacji – diagram use case i diagram klas

N/A
N/A
Protected

Academic year: 2021

Share "Wykład 1Wprowadzenie do projektowania i programowania obiektowej aplikacji w środowisku typu CASE1.Projekt aplikacji – diagram use case i diagram klas"

Copied!
7
0
0

Pełen tekst

(1)

Wykład 1

Wprowadzenie do projektowania i programowania obiektowej aplikacji w środowisku typu CASE

1. Projekt aplikacji – diagram use case i diagram klas

(2)

2. Generowanie kodu klas – pliku nagłówkowego i modułowego

(3)
(4)

3. Wygenerowany kod w środowisku CASE

3.1. Zawartość pliku nagłówkowego - wygenerowana automatycznie

// Class: Tytul

//ANSI C++

#ifndef __TYTUL_H

//Required for current class

#define __TYTUL_H

#ifndef __IOSTREAM_H

//Required for cin and cout

#include <iostream.h>

#endif

#ifndef __CSTRING_H

//Required for cstring

#include <string.h>

#endif

class Tytul {

char tytul;

//Attribute data member

int ISBN;

//Attribute data member

char Autor;

//Attribute data member

protected:

public:

//Default constructor alternative to compiler provided default constructor

//Ensure correct initial values

//Initialization list has members in the order declared

//Association object data member pointers initialized to null association object

Tytul ();

//Constructor with arguments

//Update to argument list to initialize base class data members, //e.g. (int aNumber) : BaseClass (aNumber)

Tytul ( char atytul, int aISBN, char aAutor ) ;

Tytul (const Tytul& aTytul );

//Copy Constructor

Tytul& operator= (const Tytul& aTytul);

//Operator= Assignment Operator

int operator== (const Tytul& aTytul) const;

//Operator== Equality Operator //Operator<< for cout

friend ostream& operator<< (ostream& os, const Tytul& aTytul);

(5)

friend istream& operator>> (istream& is, Tytul& aTytul);

//Operator>> for cin

char gettytul() const

//Get accessor function for non-static attribute data member

{ return tytul; }

int getISBN() const

//Get accessor function for non-static attribute data member

{ return ISBN; }

char getAutor() const

//Get accessor function for non-static attribute data member

{ return Autor; }

//Set accessor function for non-static attribute data member

void settytul (const char atytul) { tytul = atytul; }

//Set accessor function for non-static attribute data member

void setISBN (const int aISBN) { ISBN = aISBN; }

//Set accessor function for non-static attribute data member

void setAutor (const char aAutor) { Autor = aAutor; }

virtual ~ Tytul ( ) { }

//Destructor - Delete any pointer data members that used new in constructors //Destructor should be virtual if and only if class contains at least one virtual function

//Objects destroyed in the reverse order of the construction order

};

#endif

3.2. Zawartość pliku modułowego – wygenerowana automatycznie

// Class: Tytul

//////////////////////////.cpp file/////////////////////////////////////////////////////

#include "Tytul.h"

// Functions for class Tytul

//Default constructor alternative to compiler provided default constructor

//Association object data member pointers initialized to null association o

bject

Tytul::Tytul () : tytul(0), ISBN(0), Autor(0)

{

//Initialization of array of 1:M association objects to null association objects

(6)

}

//Constructor with arguments

//Update to argument list to initialize base class data members and const data members //e.g. (int aNumber) : BaseClass (aNumber) , constMinimumValue (aMinimumValue)

Tytul::Tytul ( char atytul, int aISBN, char aAutor ) { tytul = atytul;

//Initialization of attributes

ISBN = aISBN;

//Initialization of attributes

Autor = aAutor;

//Initialization of attributes

//Initialization of array of 1:M association objects to null association objects

}

//Copy constructor alternative to compiler provided default copy constructor

Tytul::Tytul (const Tytul& aTytul ) { tytul = aTytul.tytul;

ISBN = aTytul.ISBN;

Autor = aTytul.Autor;

}

int Tytul::operator== (const Tytul& aTytul) const

//Operator== Equality Operator

{ return (

//Equality check for 1:1 aggregation part data members //Equality check for 1:M aggregation parts

//Update for the correct number of aggregation part objects //Equality check for 1:M association objects for shallow compare //Update for the correct number of associated objects

//Equality check for attribute data members

(tytul == aTytul.tytul) &&

(ISBN == aTytul.ISBN) &&

(Autor == aTytul.Autor) );

}

//Operator= Assignment Operator alternative to compiler provided operator=

Tytul& Tytul::operator= (const Tytul& aTytul) { if (this == &aTytul) return *this;

tytul = aTytul.tytul;

ISBN = aTytul.ISBN;

Autor = aTytul.Autor;

return *this;

}

//Operator<< extraction for cout

ostream& operator<< (ostream& os, const Tytul& aTytul)

{ os << "Object Attribute Values - Class Tytul" << endl;

os << "tytul: " << aTytul.tytul << endl;

os << "ISBN: " << aTytul.ISBN << endl;

os << "Autor: " << aTytul.Autor << endl;

(7)

return os;}

istream& operator>> (istream& is, Tytul& aTytul)

//Operator>> insertion for cin

{ cout << "\nEnter Object Attribute Values or 0 - Class Tytul";

cout << "\nEnter tytul : " << endl;

is >> aTytul.tytul;

cout << "\nEnter ISBN : " << endl;

is >> aTytul.ISBN;

cout << "\nEnter Autor : " << endl;

is >> aTytul.Autor;

return is;

}

3.3. Zawartość pliku z funkcją main (wykonany ręcznie)

#include "tytul.h"

#include <conio.h>

void main() {

Tytul t1('a',1,'A'),t2,t3;

clrscr();

cout<<t1;

cin>>t2;

cout<<t2;

if (t1==t2) cout<<"Tytuly sa rowne"<<endl;

else cout<<"Tytuly sa rozne"<<endl;

t3=t1;

cout<<t3;

getch();}

Cytaty

Powiązane dokumenty

5) Przechodzi do stanu waitForSearchResults po otrzymaniu komunikatu receive(announce(task,.cost),mgr) od zadania roli mgr:Manager i wysłaniu do niej komunikatu

Serwisy webowe, wzorce projektowe, obsługa baz danych..

Następnie stwórz jej obiekt i zapisz tylko część pól obiektu do pliku wykorzystując dwa różne

(1 punkt) Stwórz dowolną klasę ABC zawierającą kilka pól

• Sailor enters his personal data, specifies the period for which he want to book a boat, chooses a boat (use case yacht search) and checks its availability in the given date (use

The whole class learns the same subjects (within a specified time a week) except foreign languages (some of the children learns English and some French).. A teacher may teach

• Dla spraw prowadzonych przez kancelarię mają być pamiętane informacje takie jak: data rozpoczęcia i data zakończenia sprawy, czego dotyczyła, czy zakończyła się sukcesem,

• abstrakcyjna klasa (abstract class) (nazwa klasy napisana kursywą) – klasa nie może mieć bezpośredniego egzemplarza. • elementy statyczne (static elements) – atrybuty