Mam do zrobienia coś takiego:
1. Stwórz klasę „Student” posiadającą następujące pola (można zmienić konwencje nazewnictwa):
Imie (typu String),
Nazwisko (String) ,
Nr_albumu (integer) ,
Przedmioty ( wskaźnik do dynamicznej tablicy typu String). !!!
Opcjonalnie, dodaj metodę która pozwoli monitorować wskaźnik na konsoli (dla słabo znających możliwości debuggera): //w tym edytorze tabulacja nie działa poprawnie dlatego taki format
voidprintPointerData()
{
if(przedmioty != NULL)
{
cout<<"adreswskaźnika to: "<< (&Przedmioty) <<endl;
cout<<"wskaznikpokazujenaadres: "<< Przedmioty <<endl;
cout<<"pierwszymelementemtablicy jest Przedmioty: " <<(*przedmioty) <<endl;
//cout<<"pierwszymelementemtablicy jest przedmiot: " <<wskaznikDoTabPrzedmioty[0] <<endl;
}
}
2. Na początku programu użytkownik podaje liczbę tworzonych obiektów K i zostaje przydzielona pamięć na tablicę K obiektów typu Student. Następnie należy wczytać dane poszczególnego Obiektu z klawiatury. W czasie wczytywania każdego obiektu powinno znaleźć się zapytanie o ilość Przedmiotów N dla danego obiektu Student, a następnie dynamicznie przydzielona pamięć na N Przedmiotów oraz ich wczytanie.
3. Należy stworzyć Menu umożliwiające:
Dodanie i wprowadzenie danych nowego studenta (zwiększając pamięć o 1 obiekt klasy student)
Wyświetlenie aktualnego stanu obiektu (wyprowadzenie na ekran danych studenta wraz z tablicą przedmiotów)
Zapisanie zawartości bazy do pliku student.txt
- Przed zakończeniem programu usuń wszystkie elementy tworzone dynamicznie.
i napisałam do tej pory coś takiego:
student.cpp(plik glowny)
#include "stdafx.h"
#include "student.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int ilosc;
cout<<"Ile studentow chcesz wprowadzic ?";
cin>>ilosc;
student student1;
return 0;
}
student.h:
#ifndef MOJTYP_H_
#define MOJTYP_H
#include<iostream>
#include<string>
using namespace std;
//definicja klasy
class student {
private:
string imie;
string nazwisko;
int nr_albumu;
string *przedmioty;
int N;
public:
student();
student(string a, string b, int c);
student(string *przedm, int ile)
~student();
void w_imie(const std::string& Nimie);
void w_nazwisko(const std::string& Nnazwisko);
void w_nralbumu(int Nnr_albumu);
};
#endif
student1.cpp:
#include "student.h"
#include "StdAfx.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
student::student()
{
przedmioty = new string[0];
N = 0;
}
student::student(string a, string b, int c)
{
imie= a
nazwisko = b
nr_albumu = c
}
student::student(string *przedm, int ile)
{
N=ile;
przedm= new string[N];
scrpy(przedmioty,przedm);
}
student::~student() // zdefiniowany destruktor by zlikwidowal tablice dynamiczne tworzone w klasie
{
delete[] przedm;
delete[] przedmioty;
}
void w_imie(const std::string& Nimie){
imie=Nimie;
}
void w_nazwisko(const std::string& Nnazwisko){
nazwisko=Nnazwisko;
}
void w_nralbumu(int Nnr_albumu){
nr_albumu=Nnr_albumu;
}
niestety, wywala mi błąd o podanej treści (domyślam, że jest to coś z konstruktorem albo destruktorem, ale coś kombinowałam i niestety nie wychodzi)
1>student.obj : error LNK2019: unresolved external symbol "public: __thiscall student::~student(void)" (??1student@@QAE@XZ) referenced in function _wmain
1>student.obj : error LNK2019: unresolved external symbol "public: __thiscall student::student(void)" (??0student@@QAE@XZ) referenced in function _wmain
1>D:\student\student\Debug\student.exe : fatal error LNK1120: 2 unresolved externals