Skip to content
Snippets Groups Projects
Commit 6b637279 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele und Notizen 27.6.2024

parent 70c0c708
Branches
No related tags found
No related merge requests found
#include <stdio.h>
struct TBase
{
virtual void print ();
};
struct TInteger: TBase
{
int content;
virtual void print ();
TInteger (int i);
};
struct TString: TBase
{
const char *content;
virtual void print ();
TString (const char *s);
};
void TBase::print ()
{
printf ("Base\n");
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = s;
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
struct TBase
{
void print ();
};
struct TInteger: TBase
{
int content;
void print ();
TInteger (int i);
};
struct TString: TBase
{
const char *content;
void print ();
TString (const char *s);
};
void TBase::print ()
{
printf ("Base\n");
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = s;
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
struct TBase
{
virtual void print ();
virtual ~Base ();
};
struct TInteger: TBase
{
int content;
virtual void print ();
TInteger (int i);
};
struct TString: TBase
{
char *content;
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct TBase
{
virtual void print ();
virtual ~TBase ();
};
struct TInteger: TBase
{
int content;
virtual void print ();
TInteger (int i);
};
struct TString: TBase
{
char *content;
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct TBase
{
virtual void print ();
virtual ~TBase ();
};
struct TInteger: TBase
{
int content;
virtual void print ();
TInteger (int i);
};
struct TString: TBase
{
char *content;
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = (char *) malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class TBase
{
virtual void print ();
virtual ~TBase ();
};
class TInteger: TBase
{
int content;
virtual void print ();
TInteger (int i);
};
class TString: TBase
{
char *content;
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = (char *) malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class TBase
{
public:
virtual void print ();
virtual ~TBase ();
};
class TInteger: public TBase
{
private:
int content;
public:
virtual void print ();
TInteger (int i);
};
class TString: public TBase
{
private:
char *content;
public:
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = (char *) malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class TBase
{
public:
virtual void print ();
virtual ~TBase ();
};
class TInteger: public TBase
{
private:
int content;
public:
virtual void print ();
TInteger (int i);
};
class TString: public TBase
{
private:
char *content;
public:
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = (char *) malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TInteger *answer = new TInteger (42);
TBase *object[] = { answer,
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
printf ("The answer is: %d.\n", answer->content);
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class TBase
{
public:
virtual void print ();
virtual ~TBase ();
};
class TInteger: public TBase
{
private:
int content;
public:
virtual void print ();
TInteger (int i);
friend int main ();
};
class TString: public TBase
{
private:
char *content;
public:
virtual void print ();
TString (const char *s);
virtual ~TString ();
};
void TBase::print ()
{
printf ("Base\n");
}
TBase::~TBase ()
{
}
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (const char *s)
{
content = (char *) malloc (strlen (s) + 1);
strcpy (content, s);
}
TString::~TString ()
{
free (content);
}
int main (void)
{
TInteger *answer = new TInteger (42);
TBase *object[] = { answer,
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
printf ("The answer is: %d.\n", answer->content);
for (int i = 0; object[i]; i++)
delete object[i];
return 0;
}
#include <iostream>
#include <string>
int main ()
{
string hello = "Hello, world!";
cout << hello << endl;
return 0;
}
#include <iostream>
#include <string>
using std::string, std::cout, std::endl;
int main ()
{
string hello = "Hello, world!";
cout << hello << endl;
return 0;
}
#include <stdio.h>
#include <string>
using std::string;
int main ()
{
string hello = "Hello, world!";
printf ("%s\n", hello);
return 0;
}
#include <stdio.h>
#include <string>
using std::string;
int main ()
{
string hello = "Hello, world!";
printf ("%s\n", hello.c_str ());
return 0;
}
#include <stdio.h>
int main ()
{
char answer[100];
snprintf (answer, 100, "The answer is %d.", 42);
printf ("%s\n", answer);
return 0;
}
#include <sstream>
#include <iostream>
using std::ostringstream, std::cout, std::endl;
int main ()
{
ostringstream answer;
answer << "The answer is " << 42 << ".";
cout << answer << endl;
return 0;
}
#include <sstream>
#include <iostream>
using std::ostringstream, std::cout, std::endl;
int main ()
{
ostringstream answer;
answer << "The answer is " << 42 << ".";
cout << answer.str () << endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment