Download Systems Programming Lec1b - CPP VisualStudio and more Study notes Computers and Information technologies in PDF only on Docsity! 1 Systems Programming II Introduction to C++ Introduction to Visual Studio 2 Systems Programming II Richard Anthony, Computer Science, The University of Greenwich C++ Variables Type Name (example) Value (example) int iCount; 100 long lGameScore; 7856098045 float fFractionOfGamesWon; 0.25 double dAreaOfCircle; 7.3829178473209 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 5 Systems Programming II Richard Anthony, Computer Science, The University of Greenwich C++ Variables Strings and character arrays (3) Strings can be manipulated using a group of methods: strcpy(str1, str2); // Copy string str2 into string str1 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. 6 C++ If // Two-way decision if(iNum1 > iNum2) Do whatever is in this one statement; if(bStartFlag == true) { Do all the statements in this ‘block’; } if( (bMessageReceivedFLAG == true) && (iPlayerCount < 1) ) { Do all the statements in this ‘block’; } else // if the test turns out to be ‘false’ { Do all the statements in this ‘block’; } Systems Programming II Richard Anthony, Computer Science, The University of Greenwich 7 C++ Switch // multi-way decision switch (iMessageType) { case 1 : // Process for iMessageType = 1 ... break; case 2 : // Process for iMessageType = 2 ... break; … default : // Process for all other cases. } Systems Programming II Richard Anthony, Computer Science, The University of Greenwich 10 C++ Structures // 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; Systems Programming II Richard Anthony, Computer Science, The University of Greenwich 11 C++ Classes and Objects 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 – 9) Use example CString s1 = “John"; CString s2 = “27"; CString message = “Player: “ + s1 + “ Score: " + s2; Systems Programming II Richard Anthony, Computer Science, The University of Greenwich 12 C++ Visual Studio – Introduction 1 Project - collection of all files and configuration information to build one executable. E.g. a standalone application, or a client, OR server of a client server application. Solution – One or more projects, related in an application. E.G one project to build the client, and one to build the server in a clinet server application Views – several different ways of viewing / working with the source code and resources are provided: Solution Explorer – file oriented view Class view Resource view Systems Programming II Richard Anthony, Computer Science, The University of Greenwich