viernes, 6 de enero de 2012

C++ Clase card para almacenar y mostrar datos sobre libros

//archivo ccard.h
// Class automatically generated by Dev-C++ New Class wizard
#include <string>
#include <iostream>
#include <string.h>   // Required by strcpy()
#include <stdlib.h>
#ifndef CCARD_H
#define CCARD_H



using namespace std;

struct card{
       string titulo;
       string autor;
       int ncopias;
} c;;
// No description
class cCard
{
    public:
        // class constructor
        cCard();
        // class destructor
        ~cCard();
        void store(string tit,string aut,int n);
        void show();
};

#endif // CCARD_H
//archivo ccard.cpp
// Class automatically generated by Dev-C++ New Class wizard
#include <iostream>
#include <string.h>   // Required by strcpy()
#include <stdlib.h>
#include "ccard.h" // class's header file
using namespace std;
// class constructor
cCard::cCard()
{
    // insert your code here
    c.titulo="";
    c.autor="";
    c.ncopias=0;
}

// class destructor
cCard::~cCard()
{
    // insert your code here
   
}
void cCard::store(string tit,string aut,int n) {
     c.titulo=tit;
     c.autor=aut;
     c.ncopias=n;
}
void cCard::show(){
     cout << "Título:" << c.titulo << endl;
     cout << "Autor:" << c.autor << endl;
     cout << "Número de copias:" << c.ncopias << endl;
}

//archivo mainccard.cpp
#include <cstdlib>
#include <iostream>
#include "ccard.h"
using namespace std;

int main(int argc, char *argv[])
{
    cCard tarjeta;
    tarjeta.store("El Quijote","Cervantes",5);
    tarjeta.show();
    system("PAUSE");
    return EXIT_SUCCESS;
}

No hay comentarios:

Publicar un comentario