









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Summary about Systems Programming, Introduction to C , Introduction to Visual Studio, Variables,Strings and character arrays, multi-way decision.
Typology: Study notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!
11
22
Type Name (example) Value (example) int iCount; 100 long lGameScore; 7856098045 float fFractionOfGamesWon; 0. double dAreaOfCircle; 7. char cCode; X bool bFlag; true Example assignments iCount = 100; bFlag = false; lGameScore += 1000; dAreaOfCircle = 3.1415 * dRadius * dRadius; Arrays (sequential, indexed collection of variables, very useful within a loop) Examples: int cScore[5]; //Array of 5 integers char cName[20]; //Array of 20 chars
44
Strings and character arrays (2) To access the individual characters in a character array the index must be provided, e.g. to set the contents one character at a time: szWord[0] = ‘H’; szWord[1] = ‘E’; szWord[2] = ‘L’; szWord[3] = ‘L’; szWord[4] = ‘O’; szWord[5] = 0; // Note its not in single quotes To copy the first letter into a different character variable: char cFirstLetter; cFirstLetter = szWord[0];
55
Strings and character arrays (3) Strings can be manipulated using a group of methods: strcpy(str1, str2); // Copy string str2 into string str strcpy(szWord,”HELLO”); // This automatically adds the ‘null terminator’ 0 strncpy () // Copy the first ‘n’ characters from one string into another strcat () // Join one string on the end of another etc.
77
switch (iMessageType) { case 1 : // Process for iMessageType = 1 ... break; case 2 : // Process for iMessageType = 2 ... break; … default : // Process for all other cases. }
88
// Allow controlled iteration / repetition of section of code int iPlayerScore[10]; // Valid index values are 0 … 9 int iCount = 0; int iTotal = 0; for( iCount = 0; iCount <10; iCount++ ) // Loop repeats with iCount = 0 … iCount = 9 { iTotal += iPlayerScore[iCount]; // This loop adds the iPlayerScore values } int I; int iTotal = 0; for( i = 0; i<=100; i++ ) { iTotal += i; // This loop adds the numbers 0, 1, 2, … 99, 100 } Systems Programming II Richard Anthony, Computer Science, The University of Greenwich
1010
// A collection of variables within a defined framework // Can refer to the structure itself or its individual members, as appropriate Example struct structPlayerDetails // structPlayerDetails becomes a new type { char sName[20]; int iScore; float fProportionOfGamesWon; }; Usage structPlayerDetails player1; // Create a variable player1 of the new type structPlayerDetails player2; structPlayerDetails players[2]; // An array of two player structure items Access to members player1.iScore = 25; players[1]. fProportionOfGamesWon = 0.65;
1111
A class is a type of object (A class does not exist in code, and object does) e.g. CString is a class that defines string objects An object is an instance of a class, i.e. a variable of that type e.g. CString csName; // csName is an object, of class CString There can be many objects of the same type in a the same program, e.g. CString csPlayer1Name; CString csPlayer2Name; Objects can be grouped together in arrays, e.g. CString csPlayerName[10]; // An array of 10 CString objects (numbered 0 –
Use example CString s1 = “John"; CString s2 = “27"; CString message = “Player: “ + s1 + “ Score: " + s2;
1313
Help - Highlight an item in the code and press F
1414
Header file (.h) Defines a class (its methods, variables etc). Source file (.cpp) Contains the actual methods of the class. Must ‘include’ the header file that contains the definitions for the class #include