I wanted to create an asynchronous/non-blocking udp client server application where the client and server were supposed to chat away with each other without waiting for each other's turns. I came to know that this could be done by select()... here is my Server(Mentioning only the communication part):
At first on the server side I wrote: int rv = select(n, &readfds, &writefds, NULL, NULL);
But that led to the printing of an entire empty array on the server console when the server initialised in addition to the fact that communication between the server and client was not proper. removing "&writefds" did remove the redundant data but the improper communication issue still persists...
For this problem, you will design and implement 2 classes and then write a driver function to test these classes. The first will be a C++ class for an abstract data type color with a public enumeration type colorType that has the color values shown in Listing 10.8. Your abstract data type should have an attribute for storing a single value of type colortype and member functions for reading (readColor) and writing (writeColor) a color value as well as setting and accessing it. The function readColor should read a color as a string and store the corresponding color value in the value attribute of a type color object. The function writeColor should display as a string the value stored in the value attribute of a type color object (see Figure 7.5). Modify class circle and the driver function in Listing 10.9 to include and use this class. You'll need to remove the declaration for color in class circle. Test your modified driver function with the new color and circle classes.
The second class will be to design and implement a rectangle class similar to class circle. Be sure to incorporate the new color class you have written and tested in the first part of the programming exercise. Write a client program that asks the user to enter a shape name (circle or rectangle) and then asks the user for the necessary data for an object of that class. The program should create the object and display all its attributes.
The circle class .h and .cpp files as well as the original driver function will be supplied. You are to provide the .h and .cpp files for the new color class and the modified driver function as well as the .h and .cpp files for the rectangle class and the client program that uses all three classes.
What I have so far, and I'm pretty lost;
color.h
Code:
Code: //color.h //Color class definition #include "stdafx.h" #ifndef COLOR_H #define COLOR_H class color { public: enum colorType {black, blue, green, cyan, red, magenta, brown, lightgray, nocolor};
I'm am having a few issues with this program, they stem from passing the color.h and .cpp into another .h and .cpp, and frankly getting how those two things really fit together.
For this problem, you will design and implement 2 classes and then write a driver function to test these classes. The first will be a C++ class for an abstract data type color with a public enumeration type colorType that has the color values shown in Listing 10.8. Your abstract data type should have an attribute for storing a single value of type colortype and member functions for reading (readColor) and writing (writeColor) a color value as well as setting and accessing it. The function readColor should read a color as a string and store the corresponding color value in the value attribute of a type color object. The function writeColor should display as a string the value stored in the value attribute of a type color object (see Figure 7.5). Modify class circle and the driver function in Listing 10.9 to include and use this class. You'll need to remove the declaration for color in class circle. Test your modified driver function with the new color and circle classes.
The second class will be to design and implement a rectangle class similar to class circle. Be sure to incorporate the new color class you have written and tested in the first part of the programming exercise. Write a client program that asks the user to enter a shape name (circle or rectangle) and then asks the user for the necessary data for an object of that class. The program should create the object and display all its attributes.
The circle class .h and .cpp files as well as the original driver function will be supplied. You are to provide the .h and .cpp files for the new color class and the modified driver function as well as the .h and .cpp files for the rectangle class and the client program that uses all three classes.
color.h
Code:
//color.h //Color class definition #include "stdafx.h" #ifndef COLOR_H
I am unable to implement the insert function properly,every time i run the program i just get the first value and name,i am not getting other Id's and name.
Code: "(Header File)" #include <iostream> #include <string> using namespace std; class node { public: int ID; node (string StudentName, int IDNumber) {
Implement a recursive function named void printBack(DoublyLinkedNode<T>* node) for the class DoublyLinkedCircularList which will print out the elements in the list from back to front. The function is initially called with the first node in the list. You may not make use of the previous(prev) links
This is my solution where I got 2 out of a possible 3 marks:
template<class T> void DoublyLinkedCircularList<T> :: printBack(DoublyLinkedNode<T>* node) { if(node->next == NULL) //Correct- 1 mark return 0; else printBack(node->next); //Correct - 1 mark cout << current-> element << " "; }
Today I am refining my skills on graph theory and data structures. I decided to do a small project in C++ because it's been a while since I've worked in C++. I want to make an adjacency list for a directed graph. In other words, something which looks like: 0-->1-->3 1-->2 2-->4 3--> 4-->This would be a directed graph with V0 (vertex 0) having an edge to V1 and V3, V1 having an edge to V2, and V2 having an edge to V4, like this:
V0----->V1---->V2---->V4 | | v V3
I know that in order to do this, I will need to create an adjacency list in C++. An adjacency list is basically an array of linked lists. Okay, let's see some pseudo C++ code:
Code: #include <stdio> #include <iostream> using namespace std; struct graph{
[Code] ....
This pseudocode is currently far from the mark. And that is what -- pointers and structs in C++ have never been my strong suit. First of all, this takes care of the vertices that a vertex points to -- but what about the vertex itself? How can I keep track of that vertex? When I loop over the array, it will do me no good to only know what vertices are being pointed to, rather than also knowing what points to them. The first element in each list should probably be that vertex, and then the elements after that are the vertices it points to.
But then, how can I access this first element of the list in my main program?. I would like to be able to loop over this adjacency list to do some cool things with graphs. For example, to implement some graph theory algorithms (sorts, shortest paths, etc) using the adjacency list representation. (Also, I had a question about the adjacency list. What is different than just using a list of arrays? Why can't I just have a list with an array at each element in the list?)
The following program is designed to demonstrate class templates. The program will evaluate postfix expressions input to the console by pushing them in a stack, and then popping them and evaluating them as such, (ex. entering 3 4 + would equal 3+4 = 7).
The code is below. We are not to modify it, but to fill in the blanks, the places filled in indicated with two asterisks for a line, and one on each side for a part of a line. If I didn't know what to enter (if anything), I put three ?s. If you want to copy and compile for yourself, look for all the *s and ?s.
1) I'm turning up all sorts of errors in the main program file (prog5.cpp) having to do with stacktype.cpp. It has been removed from the program, as it is included at the end of stackType.h. Most of them are "cannot convert 'this' pointer from StackType to StackType<stack> &'. How do I fix that?
2) The program supposedly lacks a default constructor, and it keeps turning up that 's' is an array of unknown size (do I call StackType or stack or what?).
stackType.h Code: #pragma once// Catherine Stringfellow and Trey Brumley // A Stack is a data type, which stores values in an order where values are added to the top of the stack when pushed, // and when popped, remove and return the value from the top of the stack. // Class specification for Stack ADT in file StackType.h using namespace std; static const int MAXITEMS = 50;
When I ran it only the calls from doers array is called 7 times normally, and donters only one time. Why is that? When I call doers from the second loop, it prints the doers functions again....and only one call to donters is made to the first static inline donter functions __dont1()...
So i'm trying to implement the selection sort algorithm and it seems that the code is fine but...
Code: #include <cs50.h> #include "helpers.h" void sort(int values[], int n) { // TODO: implement an O(n^2) sort
[Code] ....
I keep getting these errors and i don't understand why:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status
implementing an algebra function.(a+b)(a-b).does c++ support this sort of function.Did a quick search on google and all of them suggested using libraries like boost. is there anyway to do this without a library?
So I've been working on implementing a stack data structure as an ADT, the program compiles, but when I try and push elements on top of the stack, for some reason the stack is full.
I'm making a 2D Terraria-like (side-scrolling RPG with destroyable blocks) game with SFML 2.1, and I have no clue how to correctly implement collision detection. Meaning that I have been successful at making it work, but it's not clean and definitely not dynamic.
By example, I mean design wise. What parameters should collision functions take? Where should these functions be located? The same 2 questions for collision reaction. Since I have multiple things that need to collide with each other (player with enemy, player with items, enemy with items, enemy with enemy, player with player, etc...), and the world has to be treated differently, things get complicated. There is no block class, just a vertex array, so collision with the world is based purely on coordinates taken from that array in the world class, which, considering it's the world and not something like a player or an enemy, doesn't inherit from the same base class that they do.
So this code compiles without any problem but it is not producing the correct output. I know there's a problem in either my getBlock or putBlock functions but I can't see it.
Currently the output is "Should be 32 1s: " "Should be 32 2s: "
There should be 32 1s and 32 2s and nothing is coming out.
#include <iostream> #include <fstream> using namespace std; class Sdisk { public : Sdisk(string diskname);
I'm working on a programming homework that asks us to implement all the functions of a Binary Search Tree using templated classes. I'm almost done with it but I'm sort of stuck with the last part which is the `search` function. For this part the homework asks for the following requirements
Quote
Node<T>* search(T value, Node<T>* subtree)
if the current node's value is the one we're search for, return a pointer to itif the current node's left and right subtree's are empty (both m_left and m_right are looking at nullptr) then return the nullptr to indicate we didn't find the valueif the value is less than the current node's value, return the search of the left subtreeif the value is greater than or equal to the current node's value, return the search of the right subtreeMake sure to only traverse a subtree if it's not null
I'm trying to implement a tree from an array an first I used add_left_node() and add_right_node methods (as requested in the problem I have). But I'm a bit confused about the use of pointers in this. Is using &node the same as defining *pointer=node and then using "pointer" in place of &node?
I get only the value of the first node I created. For the node's left and right values I get long numbers displayed, so I think I have interfered with the addresses.
For class we are required to implement a signature block on all our assignments. To do this I've created a Signature Block class, but I'm having trouble implementing it. When I try to compile in Dev C++ I get this error:
[Error] request for member 'toString' in 'myblock', which is of non-class type 'SignatureBlock()'
Here is the code:
Assignment1.cpp
#include <iostream> #include <string> #include "SignatureBlock.h" // Assignment 1: Requests user's name and says "Hello." using namespace std; int main(int argc, char** argv) { string name;// string to store user's name SignatureBlock myblock();// create a signature block object
i have this Stealth Injector source from internet so this program is for injecting .dll to an .exe this program was made by someone to used for cheating in online game but i need to use this program in my private server game online to tell the game client .exe the server IP, that is stored in a dll file.. the problem is i don't want the player to directly execute this program, but they need to run the game patcher first to do the patch.. so i need to put some secret parameter argument that will block player from direct execute..
i know nothing about c++ i only know that you need to use main(int argc, char *argv[]) i've try to put something like this
Code: int main(int argc, char* argv[]){ stringstream sparam; string param;
[Code].....
the code works fine but the rest of code won't executed..
i've attached the cpp and header files for you guys to check source.rar
Implementing and manipulating a Polynomial ADT using a linked list.
So far I have:
poly_ADT.h Code: typedef struct nodeT{ int coef; int powr; struct nodeT *next; } node;
[Code]...
I need to create a function that creates the polynomial using input first.
poly *poly_create (num,...) ;return a new polynomial with num terms terms are listed in order of lowest ordered-term to highest. i.e., to initialize poly 15x^6 + -9x^4 + 3x^2 call poly_create(3, 3,2, -9,4, 15,6 );
Once I do that I need to implement various functions that can manipulate the polynomial itself but I'm having trouble just with creating the polynomial itself, how to do that using a linked list and nodes?
My question is mainly about networks. I wan to implement a simple transparent proxy in C, which will filter the browsed sites according to URL blacklist (check before sending the HTTP request) and keywords in content (check the <meta> in the HTML that was responded).
How can I do this? Listen in a local socket (ex. 8080), set the proxy in my browser and according to the requests that the browser sends to me open a socket with the server, forward the browser's request to the server and forward the server's response to the browser? (Of course by applying filters in the stages where needed.
I'm struggling a bit to combine templates and operator overloading.
I'm writing a program that will be able to perform various matrix arithmetic at the end. However I'm stuck at the overloaded << and >> functions. I've defined them as I'm used to, without working with templates, however they are incorrect as I have defined them, and I'm not sure how to fix it.
I want to overload the stream insertion operator >> to read matrix data from either the keyboard or a file stream. I want to use >> to input a 3 x 3 matrix stored in a text file in the following format:
2 4 3 5 2 3 7 1 0
And similarly I want to overload the stream extraction operator << to output a matrix to the screen or file in the following format:
3 2 -1 1 -1 2 2 3 -1
Here is my work so far:
matrix.h
#ifndef MATRIX_H #define MATRIX_H #include <cassert> #include <iostream> using namespace std; template <class T> class Matrix;
So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.
Stack::Stack(){ top = NULL; bottom = NULL; } //method to push a line of text onto the stack void Stack::push(string data)