Aktuelle Notizen zum C++-Kurs (Aktuelle Notizen zum C++-Kurs), Lektion, Seite 722508
https://www.purl.org/stefan_ram/pub/aktuelles_c++ (Permalink) ist die kanonische URI dieser Seite.
Stefan Ram
C++-Kurs

Aktuelle Notizen zum C++ -Kurs

2017-11-17 Anmeldung zum Kurs TK-5452-H „Programmierung mit C++ - Aufbaukurs “ ab 25.11.2017 09.00 Uhr

Es ist mir nicht bekannt, ob dieser Kurs schon ausreichend viele Anmeldungen hat. Falls jemand teilnehmen möchte, bitte bald (beispielsweise bis Montag) anmelden, da es sonst sein könnte, daß der Kurs wegen einer zu geringen Anzahl von Anmeldungen noch abgesagt werden könnte. (Ob der Kurs schon genug Anmeldungen hat, kann die Volkshochschule Treptow-Köpenick auf Anfrage auch mitteilen.)

2017-11-15 Ausgabe einer Funktion

main.cpp

#include <iostream> // ::std::cout
#include <ostream> // <<
#include <string> // "s
#include <cstdlib> // ::std::rand

using namespace ::std::literals;

int main()

{ ::std::cout << ::std::rand << "\n"s; }

Protokoll
1
main.cpp

#include <cstdlib> // ::std::rand
#include <iostream> // ::std::cout
#include <ostream> // <<
#include <string> // "s

using namespace ::std::literals;

void f( void * o ){ ::std::cout << "f: void *: " << o << "\n"s; }

void f( bool b ){ ::std::cout << "f: bool: " << b << "\n"s; }

int main() { f( ::std::rand ); }

Protokoll
f: bool: 1

2017-11-15 Typ von »::std::rand«

main.cpp

#include <cstdlib> // ::std::rand
#include <iostream>
#include <ostream>
#include <string> // "s
#include <type_traits>

using namespace ::std::literals;

template< typename T > void describe( T const )
{ ::std::cout << "::std::is_integral< T >::value = " << ::std::is_integral< T >::value << ".\n"s;
::std::cout << "::std::is_signed< T >::value = " << ::std::is_signed< T >::value << ".\n"s;
::std::cout << "::std::is_function< T >::value = " << ::std::is_function< T >::value << ".\n"s;
::std::cout << "::std::is_object< T >::value = " << ::std::is_object< T >::value << ".\n"s;
::std::cout << "::std::is_pointer< T >::value = " << ::std::is_pointer< T >::value << ".\n\n"s; }

int main()
{ ::std::cout << "describe( ::std::rand );\n"s;
describe( ::std::rand );
::std::cout << "describe( ::std::rand() );\n"s;
describe( ::std::rand() ); }

Protokoll

describe( ::std::rand );

::std::is_integral< T >::value = 0.

::std::is_signed< T >::value = 0.

::std::is_function< T >::value = 0.

::std::is_object< T >::value = 1.

::std::is_pointer< T >::value = 1.

describe( ::std::rand() );

::std::is_integral< T >::value = 1.

::std::is_signed< T >::value = 1.

::std::is_function< T >::value = 0.

::std::is_object< T >::value = 1.

::std::is_pointer< T >::value = 0.

F:\r\j\autocomp\main.cpp:9:47: warning: all parameters should be named in a function [readability-named-parameter]

template< typename T > void describe( T const )

^

/*unused*/

Der Typ von »::std::rand« ist also »int( * )()« (Adresse einer parameterlosen Funktion mit Rückgabetyp »int«).

Notizen

main.cpp

#include <iostream> // ::std::cout
#include <ostream> // <<
#include <string> // "s
#include <cstdlib> // ::std::rand

using namespace ::std::literals;

void f( void * ){ ::std::cout << "f: void *\n"s; }

void f( bool ){ ::std::cout << "f: bool\n"s; }

void g( void * ){ ::std::cout << "g: void *\n"s; }

void g( bool ){ ::std::cout << "g: bool\n"s; }

void g( void( * )() ){ ::std::cout << "g: non-matching function pointer\n"s; }

void h( void * ){ ::std::cout << "h: void *\n"s; }

void h( bool ){ ::std::cout << "h: bool\n"s; }

void h( int( * )() ){ ::std::cout << "h: matching function pointer\n"s; }

int main()

{ ::std::cout << ::std::rand << "\n"s;

f( ::std::rand );

g( ::std::rand );

h( ::std::rand ); }

Protokoll

1

f: bool

g: bool

h: matching function pointer

2016-11-27

Java-Programmierer sollte nicht ohne guten Grund "new" verwenden.

2016-02-23

Zeitplan

18.40 Behandlung von Uebungsaufgaben
19.00 Definition von Wertfunktionen
19.20 Definition von Parametern

19.40 ?:
20.00 if
20.20 while

20.40 Graphik und Matrizen (Aufbaukurs / Windows-Programmierung)
21.00 Behandlung eventueller weiterer Themenwuensche
21.20

Hinweis Im Herbst 2016 wird in Treptow-Köpenick vermutlich ein Grund- und Aufbaukurs zu C++ mit jeweils 32 UE angeboten werden. Andere Kurse haben nur 24 oder sogar nur 16 UE.

2016-02-23

Die Periode der üblichen Implementation der Funktion »::std::rand« beträgt 2³¹-1.

2016-02-23

/* In C++ gibt es viele verschiedene Moeglichkeiten, Vektoren
und Matrizen darzustellen: Reihungen, ::std::vector, valarray
oder ::std::array. Fuer ernsthafte Anwendungen sollte die
Bibliothek "Blitz++" verwendet werden.

Dieses Programm verwendet ::std::array und zeigt die Multiplikation
einer Matrix m mit einem Vektor v. Das Ergebnis findet sich dann
im Vektor p wieder.

1 2 3 = v
1 3 4
m = 2 6 8
9 0 12 */

#include <initializer_list>
#include <iostream>
#include <ostream>
#include <array>
#include <string>
using namespace ::std::literals;

int main()
{ ::std::array< int, 3 >v{ { 1, 2, 3 }};
::std::array< std::array< int, 3 >, 3 >m ={ { { { 1, 3, 4 }}, { { 2, 6, 8 }}, { { 9, 0, 12 }}}};
::std::array< int, 3 >p{ { 0, 0, 0 }};
for( int i=0; i < 3; ++i )for( int j = 0; j < 3; ++j )p[ i ]+=( m[ i ][ j ]*v[ j ]);
for( int i=0; i < 3; ++i )::std::cout << p[ i ]<< "\n"s; }

2016-02-23 CPY-DML

Dies ist ein Beispiel für ::std::vector.

#include <iostream>
#include <ostream>
#include <vector> // ::std::vector
#include <iterator> // std::ostream_iterator
#include <numeric> // ::std::iota
#include <algorithm> // ::std::random_shuffle
#include <random>


int main()
{ ::std::vector< int >v( 49 );
iota( v.begin(), v.end(), 1 );
::std::shuffle( v.begin(), v.end(), ::std::mt19937{ ::std::random_device{}() } );
copy( v.begin(), v.begin() + 6, ::std::ostream_iterator< int >( ::std::cout, " " )); }

2016-02-23

// Nebulabrot / Buddhabrot generator.
// Brought to you by Wikipedia...
// Written by User:Evercat
//
// Released under the GNU Free Documentation License
// or the GNU Public License, whichever you prefer:
// November 23, 2004
//
// This code is lame and confusing. I apologise.
// As I like to point out, my C is self-taught.
//
// Note: some folk mention possible improvements on the talk page:
// http://en.wikipedia.org/wiki/User_talk:Evercat/Buddhabrot.c

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define OUTFILE "buddhabrot"

////////////////////////////////////////////////////////////////////////////////////

#define WIDTH 1024
#define HEIGHT 768

#define CENTRE_X -0.451 // For full set try -0.451 by 0
#define CENTRE_Y 0
#define ZOOM 310 // Try 310

#define SOURCE_COLUMNS (WIDTH * 10) // These lines control the number of source values iterated.
#define SOURCE_ROWS (HEIGHT * 10) // Try WIDTH and HEIGHT * 10

#define UPDATETICK 100 // Report status every nth column reached

#define RED_MULTIPLIER 0.09 // Multiply the number of hits in a pixel by these values
#define GREEN_MULTIPLIER 0.11 // (needs to be lower the greater the number of source
#define BLUE_MULTIPLIER 0.18 // values and iterations, else image will be too bright)

#define COLOUR_OFFSET -230 // This value is added to the number of hits before a pixel is drawn.
// It needs to be lower the more source columns/rows there are.
#define RED_ITERATIONS_LOWER 0
#define RED_ITERATIONS_UPPER 1000
#define GREEN_ITERATIONS_LOWER 0
#define GREEN_ITERATIONS_UPPER 1000
#define BLUE_ITERATIONS_LOWER 0
#define BLUE_ITERATIONS_UPPER 1000

#define SOURCE_LEFT_X -2.102613
#define SOURCE_RIGHT_X 1.200613
#define SOURCE_TOP_Y -1.237710
#define SOURCE_BOTTOM_Y 1.239710

#undef RANDOM_SOURCE

#define OPTIMISE // Don't bother iterating some values obviously in the set.

#define reduce(foo) (foo) // Macro to reduce colours, can use sqrt(n), log(n), etc, or just (n)

////////////////////////////////////////////////////////////////////////////////////

void drawpath(double x, double y, double target_startx, double target_starty, double pixel_width);
double rnd (void);
void drawbmp (char * filename);

////////////////////////////////////////////////////////////////////////////////////

long long redcount[WIDTH][HEIGHT];
long long greencount[WIDTH][HEIGHT];
long long bluecount[WIDTH][HEIGHT];

int iterations;

double red_multiplier = RED_MULTIPLIER;
double green_multiplier = GREEN_MULTIPLIER;
double blue_multiplier = BLUE_MULTIPLIER;

////////////////////////////////////////////////////////////////////////////////////

int main (int argc, char * argv[]) {

int i, j, n; // General purpose counters
double x, y; // Source coordinates of particle being tracked
int source_column, source_row; // Source grid location
double r, s, nextr, nexts; // Values as particle is iterated through the Mandelbrot function
double x_jump, y_jump; // Distances between particles in the source grid
double target_startx, target_starty; // Top-left coordinates of drawn area
double target_endx, target_endy; // Bottom-right coordinates of drawn area
double pixel_width; // Actual distance represented by a pixel in the drawn area

char filename[200];

for (i = 0; i < WIDTH; i++)
{
for (j = 0; j < HEIGHT; j++)
{
redcount[i][j] = 0;
greencount[i][j] = 0;
bluecount[i][j] = 0;
}
}

target_startx = CENTRE_X - ((double) WIDTH / (ZOOM * 2));
target_endx = CENTRE_X + ((double) WIDTH / (ZOOM * 2));

target_starty = CENTRE_Y - ((double) HEIGHT / (ZOOM * 2));
target_endy = CENTRE_Y + ((double) HEIGHT / (ZOOM * 2));

pixel_width = (target_endx - target_startx) / WIDTH;

x_jump = ((double) SOURCE_RIGHT_X - SOURCE_LEFT_X) / SOURCE_COLUMNS;
y_jump = ((double) SOURCE_BOTTOM_Y - SOURCE_TOP_Y) / SOURCE_ROWS;

iterations = RED_ITERATIONS_UPPER;
if (GREEN_ITERATIONS_UPPER > iterations) iterations = GREEN_ITERATIONS_UPPER;
if (BLUE_ITERATIONS_UPPER > iterations) iterations = BLUE_ITERATIONS_UPPER;

// Main bit...

x = SOURCE_LEFT_X;
for (source_column = 0; source_column < SOURCE_COLUMNS; source_column++, x += x_jump)
{
y = SOURCE_TOP_Y;
for (source_row = 0; source_row < SOURCE_ROWS; source_row++, y += y_jump)
{

#ifdef OPTIMISE
if
(
(x > -1.2 && x <= -1.1 && y > -0.1 && y < 0.1)
|| (x > -1.1 && x <= -0.9 && y > -0.2 && y < 0.2)
|| (x > -0.9 && x <= -0.8 && y > -0.1 && y < 0.1)
|| (x > -0.69 && x <= -0.61 && y > -0.2 && y < 0.2)
|| (x > -0.61 && x <= -0.5 && y > -0.37 && y < 0.37)
|| (x > -0.5 && x <= -0.39 && y > -0.48 && y < 0.48)
|| (x > -0.39 && x <= 0.14 && y > -0.55 && y < 0.55)
|| (x > 0.14 && x < 0.29 && y > -0.42 && y < -0.07)
|| (x > 0.14 && x < 0.29 && y > 0.07 && y < 0.42)
) continue;
#endif
r = 0; s = 0;
for (n = 0; n <= iterations; n++)
{
nextr = ((r * r) - (s * s)) + x;
nexts = (2 * r * s) + y;
r = nextr;
s = nexts;
if (n == iterations)
{
// drawpath(x, y, target_startx, target_starty, pixel_width);
break;
} else if ((r * r) + (s * s) > 4) {
drawpath(x, y, target_startx, target_starty, pixel_width);
break;
}
}

}

if (source_column % UPDATETICK == 0)
{
printf("Reached source column: %d of %d\n", source_column, SOURCE_COLUMNS);
}

}

sprintf(filename, "%s r %d g %d b %d spp %d.bmp", OUTFILE, RED_ITERATIONS_UPPER, GREEN_ITERATIONS_UPPER, BLUE_ITERATIONS_UPPER, (SOURCE_COLUMNS / WIDTH) * (SOURCE_ROWS / HEIGHT));
drawbmp(filename);

printf("Done.\n");
return 0;
}

void drawpath (double x, double y, double target_startx, double target_starty, double pixel_width)
{
double r, s, nextr, nexts;
int n;
int xpixel, ypixel;

r = 0; s = 0;
for (n = 0; n <= iterations; n++)
{
nextr = ((r * r) - (s * s)) + x;
nexts = (2 * r * s) + y;
r = nextr;
s = nexts;

if ((r * r) + (s * s) > 4) return;

xpixel = (r - target_startx) / pixel_width;
ypixel = (s - target_starty) / pixel_width;
if (xpixel > 0 && xpixel < WIDTH && ypixel > 0 && ypixel < HEIGHT)
{
if (n >= RED_ITERATIONS_LOWER && n <= RED_ITERATIONS_UPPER)
{
redcount[xpixel][ypixel] += 1;
}
if (n >= GREEN_ITERATIONS_LOWER && n <= GREEN_ITERATIONS_UPPER)
{
greencount[xpixel][ypixel] += 1;
}
if (n >= BLUE_ITERATIONS_LOWER && n <= BLUE_ITERATIONS_UPPER)
{
bluecount[xpixel][ypixel] += 1;
}
}

}
return;
}

void drawbmp (char * filename) {

unsigned int headers[13];
FILE * outfile;
int extrabytes;
int paddedsize;
int x; int y; int n;
int red, green, blue;

extrabytes = 4 - ((WIDTH * 3) % 4); // How many bytes of padding to add to each
// horizontal line - the size of which must
// be a multiple of 4 bytes.
if (extrabytes == 4)
extrabytes = 0;

paddedsize = ((WIDTH * 3) + extrabytes) * HEIGHT;

// Headers...
// Note that the "BM" identifier in bytes 0 and 1 is NOT included in these "headers".

headers[0] = paddedsize + 54; // bfSize (whole file size)
headers[1] = 0; // bfReserved (both)
headers[2] = 54; // bfOffbits
headers[3] = 40; // biSize
headers[4] = WIDTH; // biWidth
headers[5] = HEIGHT; // biHeight

// Would have biPlanes and biBitCount in position 6, but they're shorts.
// It's easier to write them out separately (see below) than pretend
// they're a single int, especially with endian issues...

headers[7] = 0; // biCompression
headers[8] = paddedsize; // biSizeImage
headers[9] = 0; // biXPelsPerMeter
headers[10] = 0; // biYPelsPerMeter
headers[11] = 0; // biClrUsed
headers[12] = 0; // biClrImportant

outfile = fopen(filename, "wb"); // std::ios_base::out | std::ios_base::binary

//
// Headers begin...
// When printing ints and shorts, we write out 1 character at a time to avoid endian issues.
//

fprintf(outfile, "BM");

for (n = 0; n <= 5; n++)
{
fprintf(outfile, "%c", headers[n] & 0x000000FF);
fprintf(outfile, "%c", (headers[n] & 0x0000FF00) >> 8);
fprintf(outfile, "%c", (headers[n] & 0x00FF0000) >> 16);
fprintf(outfile, "%c", (headers[n] & (unsigned int) 0xFF000000) >> 24);
}

// These next 4 characters are for the biPlanes and biBitCount fields.

fprintf(outfile, "%c", 1);
fprintf(outfile, "%c", 0);
fprintf(outfile, "%c", 24);
fprintf(outfile, "%c", 0);

for (n = 7; n <= 12; n++)
{
fprintf(outfile, "%c", headers[n] & 0x000000FF);
fprintf(outfile, "%c", (headers[n] & 0x0000FF00) >> 8);
fprintf(outfile, "%c", (headers[n] & 0x00FF0000) >> 16);
fprintf(outfile, "%c", (headers[n] & (unsigned int) 0xFF000000) >> 24);
}

//
// Headers done, now write the data...
//

for (y = HEIGHT - 1; y >= 0; y--) // BMP image format is written from bottom to top...
{
for (x = 0; x <= WIDTH - 1; x++)
{

red = reduce(redcount[x][y] + COLOUR_OFFSET) * red_multiplier;
green = reduce(greencount[x][y] + COLOUR_OFFSET) * green_multiplier;
blue = reduce(bluecount[x][y] + COLOUR_OFFSET) * blue_multiplier;

if (red > 255) red = 255; if (red < 0) red = 0;
if (green > 255) green = 255; if (green < 0) green = 0;
if (blue > 255) blue = 255; if (blue < 0) blue = 0;

// Also, it's written in (b,g,r) format...

fprintf(outfile, "%c", blue);
fprintf(outfile, "%c", green);
fprintf(outfile, "%c", red);
}
if (extrabytes) // See above - BMP lines must be of lengths divisible by 4.
{
for (n = 1; n <= extrabytes; n++)
{
fprintf(outfile, "%c", 0);
}
}
}

fclose(outfile);
return;
}

2016-02-23

Tests helfen beim Lernen:

http://socrates.berkeley.edu/~kihlstrm/GSI_2011.htm

2016-02-21

#include <iostream>

constexpr double operator "" _2( long double const d ){ return d*d; }

int main(){ ::std::cout << 3.00_2 << '\n'; }

2016-02-10

http://www.nesssoftware.com/home/mwc/manpage.php?page=limits.h

http://www.nesssoftware.com/home/mwc/manpage.php

2016-02-09

http://www.stroustrup.com/applications.html, Feb 6, 2016 23:51:36 GMT.
Adobe Systems: All major applications are developed in C++
Amazon.com: Software for large-scale e-commerce.
Facebook: Several high-performance and high-reliability components.
GCC GCC now uses C++ as its implementation language [2012-08-14].
Google: web search engine, etc. Chromium browser.
Java VM core
Microsoft: Literally everything at Microsoft is built using recent flavors of Visual C++
Mozilla: Firefox browser and Thunderbird mail client (open source).
MySQL: MySQL Server (about 250,000 lines of C++) and MySQL Cluster. Arguably the world's most popular open source database.
Games: Doom III engine. Sierra On-line: Birthright, Hellfire, Football Pro, Bullrider I & II, Trophy Bear, Kings Quest, Antara, Hoyle Card games suite, SWAT, and too many others to list... Blizzard: StarCraft, StarCraft: Brood War, Diablo I, Diablo II: Lord of Destruction, Warcraft III, World of Warcraft. Quicksilver: Shanghai Second Dynasty, Shanghai Mah Jongg Essentials, Starfleet Command, Invictus, PBS's Heritage: Civilization and the Jews, Master of Orion III, CS-XII. Microsoft: all games. EA: video game engine. Byond: a "world" development platform.
Siemens: Major medical systems (often using ACE for convenience and portability).
T-Mobile (the largest German cellular operator) uses C++ for both its billing system and for most of its WAP portal -- dynamic allocation of IP addresses, etc.

Seiteninformationen und Impressum   |   Mitteilungsformular  |   "ram@zedat.fu-berlin.de" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram.   |   Eine Verbindung zur Stefan-Ram-Startseite befindet sich oben auf dieser Seite hinter dem Text "Stefan Ram".)  |   Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram. Schlüsselwörter zu dieser Seite/relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram722508 stefan_ram:722508 Aktuelle Notizen zum C++-Kurs Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd722508, slrprddef722508, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram.
https://www.purl.org/stefan_ram/pub/aktuelles_c++