Thursday, June 01, 2017
Wednesday, May 31, 2017
Thursday, April 27, 2017
In c++ the dot is an operator, what does it do
when you pass the if or of stream to a variable as a function how do you pass it
what do you put in front of a logical expression to reverse its value
4 choices: only one of them is a reserve word
++ operator : preincrement and postincrement:
Int a = 0
Int b = 0
B = ++A; means 1 is added to A then B becomes A: Preoperator
B = A++; means B becomes A then 1 is added to A: Postoperator
what is a valid char?
7 fill in the blanks, rest are multiple choice, total of 32 questions.
question 13 may want to use the compiler
For loop printing out the values of an array
DO you know the length of a string from looking at it?
calling conventions: two perspectives of a function: formal or actual: perspective
of the caller or the perspective of the called
static_cast{int}
two dimensional array
index operators
Member access specifier for a class
Inheritance: Base class and derived class?
which of the following class definitions makes the public members of the class A
class become the public members of the class B class
Question 26: Series of expressions: which one will evaluate to true? pick the one
that is ALWAYS true
Test does end with true or false questions actually
enum: understand the syntax
what is Macgyver's first name?
TO develop a program to solve a problem, you start by analyzing the problem.
when you pass the if or of stream to a variable as a function how do you pass it
what do you put in front of a logical expression to reverse its value
4 choices: only one of them is a reserve word
++ operator : preincrement and postincrement:
Int a = 0
Int b = 0
B = ++A; means 1 is added to A then B becomes A: Preoperator
B = A++; means B becomes A then 1 is added to A: Postoperator
what is a valid char?
7 fill in the blanks, rest are multiple choice, total of 32 questions.
question 13 may want to use the compiler
For loop printing out the values of an array
DO you know the length of a string from looking at it?
calling conventions: two perspectives of a function: formal or actual: perspective
of the caller or the perspective of the called
static_cast{int}
two dimensional array
index operators
Member access specifier for a class
Inheritance: Base class and derived class?
which of the following class definitions makes the public members of the class A
class become the public members of the class B class
Question 26: Series of expressions: which one will evaluate to true? pick the one
that is ALWAYS true
Test does end with true or false questions actually
enum: understand the syntax
what is Macgyver's first name?
TO develop a program to solve a problem, you start by analyzing the problem.
Tuesday, April 11, 2017
Tuesday, February 28, 2017
MidTerm Review Spring 2017
9 t/f
20 multiple choice
• char extraction operator (>>) how it behaves.
• flag control while loop do you use bool value? yes
• while loop ( ) <----- div="">
• how many times does a for loop execute/iterate. for(int i = 1; i<5 4="" div="" false="" i="" is="" so="" times.="" whenever="">
5>
----->
• know pre and post ++x(pre)/x++(post)
o ex.1
o x = 5;
o x++ = 5 //x = 6
o ++x= 7
o ex.2 a = 1;
o b = 0;
o b = ++a;
o a = 2;
o b = 2 ;
o -------------
o b = a++;
o b = 1;
• prototyping a function:
• #include
• using namespace std;
• void protoTypedFunction(int,int); the prototype
• know what an infinite loop is:
o ex: while(true)
• A while loop tell the output of it.
• Part of dev environment combines our pro./prog. from - assembler linker, decoder, complier.
• Know this something:
o cin >> x >> y;
o stdin: 5, 6; x = 5 y = 6
• interger division
• 19 / 7 = 2
• length of a string.
o string name = "Billy"
o length = 5
• cout << pow(pow(num, num), number) << endl;
o pow = power operator from cmath/math.h.
o pow(9,3) = 9^3 = 9 * 9 * 9
• Pre increment operation example. Break it down into 2 steps.
• Ifstream <--- 160.="" a="" div="" file.="" opening="" page="">
• Ascii has 128 characters
o Other one has 255 characters.
o Unicode has 65535 characters
--->Tuesday, January 24, 2017
Tuesday, November 15, 2016
WinSock Server
// WinSockServer.cpp : Defines the entry point for the console application. // #include "stdafx.h" #undef UNICODE #define WIN32_LEAN_AND_MEAN #include#include #include #include #include // Need to link with Ws2_32.lib #pragma comment (lib, "Ws2_32.lib") // #pragma comment (lib, "Mswsock.lib") #define DEFAULT_BUFLEN 512 #define DEFAULT_PORT "27015" int __cdecl main(void) { WSADATA wsaData; int iResult; SOCKET ListenSocket = INVALID_SOCKET; SOCKET ClientSocket = INVALID_SOCKET; struct addrinfo *result = NULL; struct addrinfo hints; int iSendResult; char recvbuf[DEFAULT_BUFLEN]; int recvbuflen = DEFAULT_BUFLEN; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); return 1; } ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_PASSIVE; // Resolve the server address and port iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); if (iResult != 0) { printf("getaddrinfo failed with error: %d\n", iResult); WSACleanup(); return 1; } // Create a SOCKET for connecting to server ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); if (ListenSocket == INVALID_SOCKET) { printf("socket failed with error: %ld\n", WSAGetLastError()); freeaddrinfo(result); WSACleanup(); return 1; } // Setup the TCP listening socket iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen); if (iResult == SOCKET_ERROR) { printf("bind failed with error: %d\n", WSAGetLastError()); freeaddrinfo(result); closesocket(ListenSocket); WSACleanup(); return 1; } freeaddrinfo(result); iResult = listen(ListenSocket, SOMAXCONN); if (iResult == SOCKET_ERROR) { printf("listen failed with error: %d\n", WSAGetLastError()); closesocket(ListenSocket); WSACleanup(); return 1; } // Accept a client socket ClientSocket = accept(ListenSocket, NULL, NULL); if (ClientSocket == INVALID_SOCKET) { printf("accept failed with error: %d\n", WSAGetLastError()); closesocket(ListenSocket); WSACleanup(); return 1; } // No longer need server socket closesocket(ListenSocket); // Receive until the peer shuts down the connection do { iResult = recv(ClientSocket, recvbuf, recvbuflen, 0); if (iResult > 0) { printf("Bytes received: %d\n", iResult); // Echo the buffer back to the sender iSendResult = send(ClientSocket, recvbuf, iResult, 0); iSendResult = send(ClientSocket, recvbuf, iResult, 0); if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); return 1; } printf("Bytes sent: %d\n", iSendResult); } else if (iResult == 0) printf("Connection closing...\n"); else { printf("recv failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); return 1; } } while (iResult > 0); // shutdown the connection since we're done iResult = shutdown(ClientSocket, SD_SEND); if (iResult == SOCKET_ERROR) { printf("shutdown failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); return 1; } // cleanup closesocket(ClientSocket); WSACleanup(); return 0; }
WinSock Client
// WinSockClient.cpp : Defines the entry point for the console application. // #include "stdafx.h" #define WIN32_LEAN_AND_MEAN #include#include #include #include #include // Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib #pragma comment (lib, "Ws2_32.lib") #pragma comment (lib, "Mswsock.lib") #pragma comment (lib, "AdvApi32.lib") #define DEFAULT_BUFLEN 512 #define DEFAULT_PORT "27015" int __cdecl main(int argc, char **argv) { WSADATA wsaData; SOCKET ConnectSocket = INVALID_SOCKET; struct addrinfo *result = NULL, *ptr = NULL, hints; char *sendbuf = "this is a test"; char recvbuf[DEFAULT_BUFLEN]; int iResult; int recvbuflen = DEFAULT_BUFLEN; // Validate the parameters if (argc != 2) { printf("usage: %s server-name\n", argv[0]); return 1; } // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); return 1; } ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; // Resolve the server address and port iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result); if (iResult != 0) { printf("getaddrinfo failed with error: %d\n", iResult); WSACleanup(); return 1; } // Attempt to connect to an address until one succeeds for (ptr = result; ptr != NULL;ptr = ptr->ai_next) { // Create a SOCKET for connecting to server ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); if (ConnectSocket == INVALID_SOCKET) { printf("socket failed with error: %ld\n", WSAGetLastError()); WSACleanup(); return 1; } // Connect to server. iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen); if (iResult == SOCKET_ERROR) { closesocket(ConnectSocket); ConnectSocket = INVALID_SOCKET; continue; } break; } freeaddrinfo(result); if (ConnectSocket == INVALID_SOCKET) { printf("Unable to connect to server!\n"); WSACleanup(); return 1; } // Send an initial buffer iResult = send(ConnectSocket, sendbuf, (int)strlen(sendbuf), 0); if (iResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ConnectSocket); WSACleanup(); return 1; } printf("Bytes Sent: %ld\n", iResult); // shutdown the connection since no more data will be sent iResult = shutdown(ConnectSocket, SD_SEND); if (iResult == SOCKET_ERROR) { printf("shutdown failed with error: %d\n", WSAGetLastError()); closesocket(ConnectSocket); WSACleanup(); return 1; } // Receive until the peer closes the connection do { iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0); if (iResult > 0) { recvbuf[iResult] = NULL; printf("Msg: %s\nBytes received: %d\n", recvbuf, iResult); } else if (iResult == 0) printf("Connection closed\n"); else printf("recv failed with error: %d\n", WSAGetLastError()); } while (iResult > 0); // cleanup closesocket(ConnectSocket); WSACleanup(); return 0; }
Wednesday, January 20, 2016
Wednesday, January 06, 2016
Tuesday, July 21, 2015
Wednesday, July 15, 2015
#include
using namespace std;
//cin demo with exception detection and quit
int main(void)
{
int n = 0;
char c;
while(cin)
{
cout << "Enter a int(q to quit): ";
cin >> n;
if(!cin)
{
cin.clear();
c=cin.peek();
if(c=='q')
break;
else
{
cout << "Oops try again\n";
cin.ignore(5000,'\n');
}
}
}
return 0;
}
using namespace std;
//cin demo with exception detection and quit
int main(void)
{
int n = 0;
char c;
while(cin)
{
cout << "Enter a int(q to quit): ";
cin >> n;
if(!cin)
{
cin.clear();
c=cin.peek();
if(c=='q')
break;
else
{
cout << "Oops try again\n";
cin.ignore(5000,'\n');
}
}
}
return 0;
}
Wednesday, January 16, 2013
Wednesday, January 13, 2010
Wednesday, October 01, 2008
Wednesday, September 24, 2008
Tuesday, November 20, 2007
Thursday, November 01, 2007
Friend function example
// friend_functions.cpp
// compile with: /EHsc
// http://msdn2.microsoft.com/en-us/library/h2x4fzdz(VS.80).aspx
#include
using namespace std;
class Point
{
friend void ChangePrivate( Point & );
public:
Point( void ) : m_i(0) {}
void PrintPrivate( void ){cout << m_i << endl; }
private:
int m_i;
};
void ChangePrivate ( Point &i ) { i.m_i++; }
int main()
{
Point sPoint;
sPoint.PrintPrivate();
ChangePrivate(sPoint);
sPoint.PrintPrivate();
}
// compile with: /EHsc
// http://msdn2.microsoft.com/en-us/library/h2x4fzdz(VS.80).aspx
#include
using namespace std;
class Point
{
friend void ChangePrivate( Point & );
public:
Point( void ) : m_i(0) {}
void PrintPrivate( void ){cout << m_i << endl; }
private:
int m_i;
};
void ChangePrivate ( Point &i ) { i.m_i++; }
int main()
{
Point sPoint;
sPoint.PrintPrivate();
ChangePrivate(sPoint);
sPoint.PrintPrivate();
}
Thursday, October 04, 2007
Welcome to CIS282 Fall 2007
Here are the links that Karin found to help us setup the win32 dev env:
Using the Free Visual C++ 2005 Express Edition to Develop Win32 Applications
Using the Free Visual C++ 2005 Express Edition to Develop Win32 Applications
Subscribe to:
Posts (Atom)