Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <string.h>
- extern void foo(char* m);
- using namespace std;
- static int anzahl;
- class Auto {
- int leistung = 0;
- char fabrikat[50];
- char* ptr = fabrikat;
- public:
- Auto() {
- leistung = 50;
- ptr = (char*)"skoda";
- anzahl++;
- cout << "Es gibt " << anzahl << " Auto(s)." << endl;
- }
- Auto (int l) {
- leistung = l;
- ptr = (char*)"skoda";
- anzahl++;
- cout << "Es gibt " << anzahl << "Auto(s)." << endl;
- }
- Auto (int l, char* f) {
- leistung = l;
- ptr = f;
- anzahl++;
- cout << "Es gibt " << anzahl << "Auto(s)." << endl;
- }
- ~Auto() {
- delete [] fabrikat;
- anzahl--;
- cout << "Es gibt " << anzahl << "Auto(s)." << endl;
- }
- int getAnzahl() {
- return anzahl;
- }
- int getLeistung() {
- return leistung;
- }
- void setLeistung(int l) {
- leistung = l;
- }
- void setFabrikat(char* f) {
- ptr = f;
- }
- void print() {
- cout << "Leistung: " << leistung << " Fabrikat: " << ptr << endl;
- }
- };
- int main(int argc, char *argv[]) {
- int n, leistungTemp;
- cout << "Wie viele Autos sollen erstellt werden?" << endl;
- cin >> n;
- Auto array1 [n];
- for(int i = 0; i < n; i++) {
- char * fabrikatTemp = new char[50];
- cout << "Bitte geben Sie die Leistung des Autos ein." << endl;
- cin >> leistungTemp;
- cout << "Bitte geben Sie das Fabrikat des Autos ein." << endl;
- cin >> fabrikatTemp;
- //Es wird der Standardkonstruktor verwendet und die Werte werden nach der Eingabe gesetzt
- array1[i].setLeistung(leistungTemp);
- array1[i].setFabrikat(fabrikatTemp);
- }
- for(int j = 0; j < n; j++) {
- array1[j].print();
- }
- cout << "--------------------------------" << endl;
- //Es wird der Standardkonstruktor verwendet
- Auto array2 [3] = { Auto(), Auto(), Auto()};
- for(int i = 0; i <3; i++) {
- array2[i].print();
- }
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement