Category Archives: GSP 215 (NEW)

GSP 215 Week 7 iLab Networking and a Tiny Web Server Updated

GSP 215 Week 7 iLab Networking and a Tiny Web Server Updated


TCO 1—Given a computing environment with multiple operating systems, demonstrate the ability to use the command line interface in Windows and Linux, and compile and run a program using the command line.

TCO 10—Given the importance of networking in game design, explain how computers are connected to a network, and summarize basic networking fundamentals, terminologies, protocols, and devices.




In this week’s lab, we will create two C programs to use with networking commands. The first program will read a domain name or dotted-decimal address from the command line and display the corresponding host entry. The second program will be a tiny web server used on localhost.



Part A:

In this lab, we will explore DNS mapping by creating a file named hostinfo.c. This program will read a domain name or dotted-decimal address from the command line and display the corresponding host entry. Local host will always map to

Enter the following C code into notepad. Save the file in the cygwin\home\username folder on your computer (ie: C:\cygwin64\home\gina) as hostinfo.c.

Open Cygwin, and compile the program: gcchostinfo.c –o hostinfo.



#include <stdlib.h>

#include <stdio.h>

#include <arpa/inet.h>

#include <netdb.h>


Run the program with the following domain names, and note the results. Also, choose some of your own.



Part B:

Read pages 919-927 in the book. We will be developing the tiny web server listed in the book. This web server supports the GET method. It will look for an HTML file in the current directory and will display the web page in a web browser. Please study and review the code to understand what it is doing. Feel free to extend the code as well.

Copy the C code below into notepad. Save the file in the cygwin\home\username folder on your computer (i.e., C:\cygwin64\home\gina) as tiny.c.

Compile the program: gcctiny.c –o tiny.

, at a cygwin prompt, type ./tiny 10000.

This will start the web server listening at port 10000.

Open your web browser, and type the following in the address bar: http://localhost:10000/home.html.

This will open your website using your own tiny web server. To stop your tiny web server, press control + c in cygwin.


Include a screenshot below of your web page working in a browser.


C Code:

//Tiny web server code

#include <stdlib.h>

#include <stdio.h>

For more Assignments visit

GSP 215 Week 7 Homework Networking Commands Updated

GSP 215 Week 7 Homework Networking Commands Updated

Week 7 Homework—Networking Commands


This week’s homework will focus on basic networking commands.

Display IP configuration settings.

1.      Open a Windows CLI (Start->run type in cmd and press enter)

2.      The ipconfig command is used to view a computer’s IP address. When your system is resolving the DNS addresses incorrectly, flushing the DNS using ipconfig –flushdns is a helpful command. To release and renew an IP address, use ipconfig – release and ipconfig –renew.


What does subnet mask mean? What does default gateway mean?



3.      Ping is used to verify connectivity to a network. Ping a web address of your choice, and press control + c to stop it.


Paste the screenshot below.



4.      Run traceroute on a website address of your choice (control + c to stop).  Example:



5.      Nslookup is helpful to know if the DNS is working correctly. Run nslookup against a hostname to see if the name is resolved. Example:


6.      The netstat command has many options and gives a lot of information about your network. The –a option will show you the open ports on your computer.


7.      If you have a Windows machine, go to the control panel on your computer. Then pick network and sharing center.



Under view your active networks, you will see a link next to connections (in the above picture it is wired). Click on the link you see next to connections, then click on properties.  Select Internet protocol version 4 (TCP/IPv4), and click properties.


Note that changing these settings may disconnect you, so click cancel rather than OK.

•     To obtain IP settings automatically, click obtain an IP address automatically, and then click OK.

•     To specify an IP address, click use the following IP address, and then in the IP address, subnet mask, and default gateway boxes, type the IP address settings.


Take a screenshot of your settings.


Why would you choose

For more Assignments visit

GSP 215 Week 6 iLab Virtual Memory Updated

GSP 215 Week 6 iLab Virtual Memory Updated


Week 6 Lab—Virtual Memory


TCO 9—Given the need to support the runtime creation of varying quantities of data objects, learn how dynamic memory allocation can provide this capability in a very efficient way.

TCO 8—Given the need to understand virtual memory, describe how memory allocation and paging are used to give a computer program access to more memory than physically available.




In this week’s lab, you will override the new and delete operators for an implementation of linked list.




Point distribution for this activity

Lab Activity

Document       Points possible            Points received

Code and screenshot   40       

Total Points     40       




Generally, the default implementation of new and delete is sufficient for a given program. At times, you may want to specialize memory allocation for advanced tasks. You may want to allocate instances of a certain class from a particular memory pool, implement your own garbage collector, or caching.


We will override the new and delete operator in this lab. When overriding these operators, both need to be overridden. The new operator allocates memory and creates an object. The delete operator deallocates memory.


We will be implementing a linked list class and overloading the new and delete operator. We can improve the speed of allocating new nodes by keeping a list of deleted nodes and reusing the memory when new nodes are allocated.

The code for the linked list is below. You may also use your own implementation of linked list.

The overloaded new operator will check a freelist to recycle a node before going to the heap and getting one that way. The delete operator will add the node to the freelist.

Hint: Use the following in the Node class.

void * operator new(size_t);

void operator delete(void*);

static void printFreelist();

After the class Node definition, be sure to set the freelist to NULL.

Node* Node::freelist=NULL;


Implement Node::printFreelist() as well, and in the Main, include calls to


to see the nodes in the free list.

Original C++ Code:

#include <iostream>

using namespace std;

For more Assignments visit

GSP 215 Week 6 Homework Virtual Memory Updated

GSP 215 Week 6 Homework Virtual Memory Updated


GSP 215 Week 6 Homework Assignment


Week 6 Homework—Virtual Memory


This week’s homework problems will be completed in the book.

Complete problems 9.12 and 9.13 below.

Review Section 9.6.4 as a guide.

Problem 9.11 is done below to help you.

9.11. For the given virtual address, indicate the TLB entry accessed, the physical address, and the cache byte value returned. Indicate whether the TLB misses, whether a page fault occurs, and whether a cache miss occurs. If there is a cache miss, enter – for cache byte returned. If there is a page fault, enter – for PPN, and leave parts C and D blank. You will need to use the tables on page 796 for PPN translation (page table b).

For more Assignments visit

GSP 215 Week 5 iLab Memory Updated

GSP 215 Week 5 iLab Memory Updated


Week 5 Lab—Memory


TCO 6—Given the fundamental role of processes in organizing a computer’s flow of execution, be able to explain how multitasking/multiprocessing works, including what constitutes a context switch.

TCO 7—Given that performance of a game is dominated by the speed of various parts of the memory system, understand algorithms used to manage memory on a computer.




In this week’s lab, you will create a memory viewer using a combination of C and C++ to create an interactive tool for visualizing memory.




This lab is based on this video series by Professor Michael Vaganov:

Please watch the video series, which will walk you through creating a memory viewer step by step. Each video builds on the successive one until you have an interesting memory viewer at the end.

The program starts with Hello World in C++.

#include <iostream>

int main()


            std::cout<<”Hello world”<<std::endl;

            return 0;


Work through the code with the author. Submit your code and screenshot of the final project to the Dropbox.

For more Assignments visit

GSP 215 Week 5 Homework Memory Leaks Updated

GSP 215 Week 5 Homework memory Leaks Updated

Week 5 Homework—Memory Leaks

Memory leaks are bugs in C++ applications that can cause performance problems with your application or even causing it to crash. A memory leak is the result of failing to deallocate memory that was previously allocated. In C++ the commands


#include <stdlib.h>

#include <crtdbg.h>

will enable the debug heap functions. After enabling the debug heap functions, place a call to _crtDumpMemoryLeaks() before an application exit point.

Given the following code, run this code in debug mode. The memory leak report will appear in the Output Window with the debug option. It should look something like this.


The output will look like the following.

Detected memory leaks!

Dumping objects ->

{142} normal block at 0x0079A948, 25 bytes long.


{141} normal block at 0x0079A8F8, 20 bytes long.

 Data: <Sheldon         > 53 68 65 6C 64 6F 6E 00 CD CDCDCDCDCDCDCD

Object dump complete.

The information displayed is: the memory allocation number (142), block type (normal), the hexadecimal memory location (0x0079A948), and the size of the block (25 bytes long).

Rewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.



#include <stdlib.h>

#include <crtdbg.h>

#include <string>

void memLeak()


                        int *p = new int;

            char * string1 = new char[20];

            char * string2 = new char[25];

            strcpy(string1, “Sheldon”);



            delete p;


int main(intargc, char* argv[])





            return 0;          



C++ code with no memory leaks:



For more Assignments visit

GSP 215 Week 4 Homework Optimizing Program Performance Updated

GSP 215 Week 4 Homework Optimizing Program Performance Updated


Optimizing Program Performance


A programmer must write correct code that is clear and concise. There are also circumstances in which a programmer must write fast and efficient code. Processing video frames in real time must be fast. We will talk about ways to optimize code.

Given the following code, perform these operations to optimize the code. See Chapter 5 in the book for more details on code optimization. Please use comments to document all optimizations you have made to the code.

1.      Using switch instead of if

2.      Eliminating length calls out of the loop test

3.      Put the most used variables first when initializing variables

4.      Use prefix operations rather than postfix operations

5.      Loop unrolling—increase the number of elements computed in each iteration of a loop (i.e. instead of processing arrays separately, if you have two arrays of the same length, process them in parallel)

6.      Any other improvements you want to make


#include <iostream>

#include <vector>

#include <string>

using namespace std;


#include <iostream>

#include <vector>

#include <string>

using namespace std;


int main()


            //This program stores the items purchased at the grocery store. The price vector stores the prices for each item purchased.

            //The product name vector stores the products purchased and the category vector stores which category the item falls under.

            //Frozen foods have a 10% discount, snacks has a 5% discount, and produce has a 15% discount.

            //The total amount of items purchased should be calculated with a 7% tax rate.

       double sum;

            double tax,totalAmount;


            vector<double> price;


            vector<char> category;







For more Assignments visit

GSP 215 Week 3 iLab Machine-Level Representation of Programs Updated

GSP 215 Week 3 iLab Machine-Level Representation of Programs Updated

Week 3 Lab Machine-Level Representation of Programs

TCO 3—Given the need to understand and describe performance bottlenecks, acquire an understanding of how C and C++ is translated into machine code.


In this week’s lab, you will key in and compile a C++-supplied program. Using the instructions provided, you will proceed to inspect, comment, and produce representative assembly code.




We will look at C code versus machine code. Write the following code in cygwin using vi and save it as code.c.

Part B:

Linux and Windows show assembly in different formats. The code differences are shown below.

Copy the code below into a new Visual Studio Project. Compile the C++ code. In the Solution Explorer, right click on the .cpp file and choose properties.

For more Assignments visit

GSP 215 Week 3 Homework Representing and Manipulating Information Updated

GSP 215 Week 3 Homework Representing and Manipulating Information Updated


GSP 215 Week 3 Homework Assignment


Week 3 Homework—Representing and Manipulating Information


Structures are a mechanism for creating a data type to aggregate multiple objects into a single unit. All the components of a structure are stored in a contiguous region of memory and a pointer to a structure is the address of its first byte. To access the fields of a structure, the compiler generates code that adds the appropriate offset to the address of the structure.

The example on the book on page 242 shows the following structure.

struct rec {

            int i;

            int j;

            int a[3];

            int *p;


This structure contains four fields: two 4-byte int’s, an array consisting of three 4-byte int’s, and a 4-byte int pointer giving a total of 24 bytes. j is offset 4 bytes.

    0                          4                          8                     16                      20                      24

i j a[0] a[1] a[2] p


Assuming variable 4 is of type struct rec * and is in register %edx, the following code copies element r->i to element r->j.

movl  (%edx), %eax    // Get r->i

movl %eax, 4(%edx) //Store r->j  To store into the field j, the code adds offset 4 to the address of r

Consider the following structure declaration containing a structure within a structure, and answer the following questions.

struct person{

            struct size{

            int height;

            int weight;


            int *hp;

            int games[2];

}person1, person2;

1.      How many total bytes does the structure require?

height weight hp games[0] games[1]


2.      What are the offsets in bytes of the following fields?

s.height: ______________




3.      The compiler generates the following assembly code for the body of str_init (shown below).


movq    16(%rbp), %rax     //Get p1 into register %rax

movl    4(%rax), %edx      //Get p1->s.weight store in register %edx

movq    16(%rbp), %rax     //Get p1 into register %rax

movl    %edx, (%rax)       //Store in p1->s.height

movq    16(%rbp), %rax     //Get p1 into register %rax

leaq    4(%rax), %rdx      //Compute address of p1->s.weight in register %rdx

movq    16(%rbp), %rax    //Get p1 into register %rax

movq    %rdx, 8(%rax)     //Store in p1->hp


4.      On the basis of this information, fill in the missing expressions in the code for str_init.

   void str_init(person *p1)


      p1->s.height = _____________;

      p1->hp = _________________;


5.      How would you call str_init with the structperson1 passed to it? 

For more Assignments visit

GSP 215 Week 2 iLab Binary Representation of Information Updated

GSP 215 Week 2 iLab Binary Representation of Information Updated

GSP 215 Week 2 iLab

Week 2 Lab—Binary Representation of Information


In this lab, we will be using cygwin and Visual Studio to write C++ code to illustrate floating point error and bitwise operations

Part A:

The goal of this exercise is to introduce you to an important aspect of numerical computing: numerical error. Games use floating point as the primary number representation for almost everything. Coordinate data stored as (x,y,z) is used to represent vertices, which in turn are used to represent triangles, which themselves are used to represent 3D objects.

Digital representation of any number must be accomplished with a fixed number of bits, typically 32. However, one third, for example, has no finite representation in fixed-point binary; that is, it would require an infinite number of bits unless one uses floating point. Computation with real numbers can quickly produce results that cannot fit into 32 bits. When this happens, numbers are rounded to the closest representable number. This introduces numerical error. Evaluating a series of expressions can result in a large error, as demonstrated in this lab.

Use single precision floating point for all numbers. Variables need to be declared as float, and constants should be followed by an f suffix, as in 3.14f.

1.      Compute the square root of 501.0f, and store the result in a variable float x.

2.      Multiply x by itself. Ideally, this would = 2. What do you get?

3.      Multiply x by itself again. Ideally, this would = 4. What do you get?

4.      Subtract x from the constant 251001.0f. Ideally, this should = 0.0. What do you get?

5.      Compute the multiplicative inverse of (meaning 1/x). In order to avoid dividing by 0.0, first test if x!= 0.0, and only compute inverse if this is true. What do you get?

6.      Copy and paste your source code into the lab report below, and paste a screenshot. See an example of the screenshot below.

C++ Code:


See example below:

Part B:

Color displays use blends of red, green, and blue (RGB) light to create the colors you see. The digital representation of this concept is to store each red, green, and blue component as an eight-bit unsigned number. The value 255 represents the maximum displayable brightness of a single component, the color 0 represents no intensity/light, and 128 is halfway between the two extremes. Below are some triples of RGB values and what color they represent.

0, 0, 0


255, 255, 255

bright white

255, 0, 0

bright red

0, 128, 0

medium green

128, 128, 0

medium yellow

A digital image is a two-dimensional array of RGB values, where each RGB corresponds to an on-screen pixel.

For a better understanding, open an image using the program paint (under the accessories menu). Select the color menu, then edit colors, then define custom colors, and play around in the right-hand side of the pane where you can type in RGB component numbers to see what color they represent.

Because each component is only eight bits, the 24 bits required for RGB is typically stored in a single 32-bit word rather than separately. This is called a packed RGB format. This is what is used to drive all computer displays. The hexadecimal representation of orange (full red, half green, no blue) is 0x00FF0800.

The representation of half red, half green, half blue is 8421504, in hexadecimal it is: 0×00808080.

Write two functions using only shifts and bit-wise logical operations. One takes individual red, green, and blue components as input and returns a single 32-bit word in packed format. The second does the inverse, which is called unpacking. Test your code with some simple examples. First pack the red, green, and blue, and then unpack them to see that you get what you started with. Pay attention to the types of all input and return values to make sure that they use the least number of bits required. All of these should be unsigned numbers (there are no negative colors).

You will need to use shift operator. x=y<<4 assigns x the result of shifting y to the left four bits. You will also be using bitwise & (AND) and | (OR). Hint: in unpack, you will need to write code like this: r2=(rgb>>16) &0xff; to unpack the value for red. To pack the values, you will need something like this: rgb = r<<16|g<<8|b;


#include <iostream>

using namespace std;




 int pack (int r, int g, int b);

For more Assignments visit