Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Clasa de baza: articol
- atribute: titlul, cota(nr de identare)
- derivata: carte
- atribut: autor
- constructor init, si copiere , get & set, citire & afisare, supra incarcarea lui =
- */
- #pragma warning(disable:4996)
- #include <conio.h>
- #include <iostream>
- #include <stdio.h>
- //#include <stdlib.h>
- using namespace std;
- class articol{
- protected:
- char titlu[50];
- int cota;
- public:
- articol(char titlu[], int cota) {
- strcpy(this->titlu, titlu);
- this->cota = cota;
- }
- articol(articol& random) {
- this->cota = random.cota;
- strcpy(this->titlu, random.titlu);
- }
- ~articol() {
- cout << "\ndestructor articol activat \n";
- }
- char * getTitlu() {
- return this->titlu;
- }
- int getCota() {
- return this->cota;
- }
- void setTitlu(char random[50]){
- strcpy(this->titlu, random);
- }
- void setCota(int random) {
- this->cota = random;
- }
- void citire() {
- cout << "\nNume Titlu:";gets_s(this->titlu);
- cout << "\nCota: "; cin >> this->cota;
- }
- void afisare() {
- cout << "\n\nNume Titlu articol: " << this->titlu;
- cout << "\nCota: " << this->cota;
- }
- articol & operator = (articol random) {
- this->cota = random.cota;
- strcpy(this->titlu, random.titlu);
- return *this;
- }
- };
- class carte: public articol {
- protected:
- char autor[50];
- public:
- carte(char titlu[], int cota,char autor[]):articol(titlu,cota) {
- strcpy(this->autor, autor);
- }
- carte(carte& random):articol(random) {
- strcpy(this->autor, random.autor);
- }
- ~carte() {
- cout << "\ndestructor carte activat\n";
- }
- char * getAutor() {
- return this->autor;
- }
- void setAutor(char random[50]){
- strcpy(this->autor, random);
- }
- void citire() {
- this->articol::citire();
- //cout << "\nNume Titlu: ";gets_s(this->titlu);
- //cout << "\nCota: "; cin >> this->cota;
- cout << "\nNume Autor: "; gets_s(this->autor);
- }
- void afisare() {
- this->articol::afisare();
- //cout << "\n\nNume Titlu articol: " << this->titlu;
- //cout << "\nCota: " << this->cota;
- cout << "\nAutor: " << this->autor;
- }
- carte & operator = (carte random) {
- strcpy(this->autor, random.autor);
- return *this;
- }
- };
- void main() {
- articol Frentzy("Frentzy", 21);
- Frentzy.afisare();
- cout << endl;
- cout << "getCota() = " << Frentzy.getCota() << endl;
- cout << "getTitlu() = " << Frentzy.getTitlu() << endl;
- Frentzy.setCota(20);cout << "getCota() = " << Frentzy.getCota() << endl;
- Frentzy.setTitlu("Aleator");cout << "getTitlu() = " << Frentzy.getTitlu() << endl;
- cout << endl << "citire:"<<endl;
- Frentzy.citire();
- Frentzy.afisare();
- articol Test1(Frentzy);
- Test1.afisare();
- articol Test2("Test2", 2);
- Test2.afisare();
- Test2 = Frentzy;
- Test2.afisare();
- cout << "\n////////////////////////////////////////////////\n";
- cout << endl;
- carte ceva("Frentzy", 21, "Profesor Zgarie-Branza");
- ceva.afisare();
- cout<<"\ngetAutor()="<<ceva.getAutor()<<endl;
- ceva.setAutor("Autor");
- carte ceva_temp(ceva);
- cout << "\n\ncopierea lui ceva_temp cu ceva";
- ceva_temp.afisare();
- cout << "\n\n------------------\n";
- carte etc("1", 1, "1");
- etc.afisare();
- etc = ceva;
- etc.afisare();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement