C :: Structured Lists From Text

Apr 5, 2013

New to this C stuff, and was going through Kochan's book Programming in C and got to chapter 9 structured lists.There's this problem that requires you to set a Variable N that calculates days.

N = 1461 x f(year, month) / 4 + 153 x g(month) / 5 + day
where
f(year, month) = year-1 (if month <=2)
=year (otherwise)

g(month) = month+13 (if month <=2)
= month+1 (otherwise) Code:
struct date {
}

[code]....

I was having issues getting the right values for N so I tried to see what T1.year gives me when I type in firstDay.month=02, firstDay.day=08 and firstDay.year=1999, and I got 8. According to book I should be getting 1998.

View 2 Replies


ADVERTISEMENT

C/C++ :: Dating Service Program Using Text File And Linked Lists

Jun 16, 2013

I'm new to programming, and I'm working on my second c++ program right now. Its a dating service where you read data from an input .txt file and store into a linked list, so then you can search, and modify the data. The text file is in this format:

M Dr.Gregory House,237-8732 7 Vicodin,Guitar,Piano,Motorcycles,Television,Food,W hiteboards.endl; (all on a single line).

First, is the sex (M or F), then the person's name, phone number, number of interests, then a list of their interests (with commas between each one, and a period at the end.) and then if they have a match you put their name there and put endl; after.

The main problem I'm having is setting up the link list, how to get it to read those as variables in the text, I know you have to use delimiters, but I can't quite figure out how to use them. You also have to keep two lists, one for males, and one for females in the output file. How do I do this? Is that a double linked list?

Here is the code so far (I know it isn't much..)

#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <cstring>  
using namespace std;  
//Functions
void echoPrint();

[Code] .....

View 2 Replies View Related

C++ :: Processing Structured Arrays - Too Many Initializer Values

Apr 22, 2013

I working on an assignment that processes an array of structs. In the main function I am attempting to declare an array of Author structures with 3 elements. It is supposed to be initialized to set all of the string fields (the names and book titles) to "NONE", and the double fields (the prices) to zero. This is supposed to be done in one statement, not using loops. Here is what I have.

struct BookInfo struct Author
{ {
string title; string authorName;
double price; BookInfo books[SIZE] //SIZE = 3
}; };

//prototype for function to print the content of array on screen
void showInfo(Author a[], int size);

[Code] .....

I was under the impression that an array can only hold the values of one data type. So doubles and strings in the same array doesn't make sense to me. However, that's the example my teacher drew up. The error keeps telling me that there are too many initializer values.

View 4 Replies View Related

C++ :: Structured Data - Nesting Triangles Using Structs And Doing Some Geometric Calculation

Sep 8, 2013

nestedTriangles.cpp description:

The program takes as input a pair of triangles, specified be giving the coordinates of each trangle's vertices. It then determines if either triangle is "nested" within the other, meaning that one triangle lies entirely within the interior of the other.

Pseudocode:

One triangle lies within another if and only if all three vertices of the first triangle lie within the interior of the second triangle.

Suppose that we have a triangle with vertices A, B, and C, described by the coordinates (xA, yA), (xB, yB), and (xC, yC), respectively. The sides of the triangle are the line segments AB, BC, and CA.

A line passing through two points (x1, y1) and (x2, y2) can be considered to be the set of points (x,y) satisfying the equation

f(x,y) = 0
where f(x,y) is given as
f(x,y) = (x - x1) (y2 - y1) - (y - y1) (x2 - x1)

One of the interesting things about that f(x,y) is that we can use it to determine which "side" of the line an abitrary point (x,y) is on:

If f(x,y) = 0, the point is exactly on the line. All points for which f(x,y) > 0 are on one side of the line, and All points for which f(x,y) < 0 are on the other side So the problem of determining whether a point (x,y) is on the inside of a trangle can be checking the sign of f(x,y) for each of the three lines making up the triangle. A complicating factor is that we don't know, for any given triangle, whether those three signs should be all positive, all negative, or some mixture of the two.

The centroid of a triangle can be computed as the "average" of the x and y coordinates of the vertices:

xcen = (xA + xB + xC)/3
ycen = (yA + yB + yC)/3

This point (xcen, ycen) is definitely inside the trangle (unless the triangle is "degenerate" and has no interior points). The problem of determining whether (x,y) is on the inside of a triangle can therefore be resolved by checking to see if it is on the same side of each of the trangle's line segments as (xcen, ycen).

What I need:

I want to fill in the missing bodies for the functions eval and areOnSameSideOf, which manipulate line segments. I think calling eval from within areOnSameSideOf will simplify the implementation of the latter.

Code:
#include <iostream>
using namespace std;
/**
* 2D Cartesian coordinates
*/

[Code]....

View 2 Replies View Related

C++ :: Structured Data / Nesting Triangles Using Structs And Doing Some Geometric Calculation?

Sep 8, 2013

nestedTriangles.cpp description:

The program takes as input a pair of triangles, specified be giving the coordinates of each trangle's vertices. It then determines if either triangle is "nested" within the other, meaning that one triangle lies entirely within the interior of the other.

Pseudocode:

One triangle lies within another if and only if all three vertices of the first triangle lie within the interior of the second triangle.Suppose that we have a triangle with vertices A, B, and C, described by the coordinates (xA, yA), (xB, yB), and (xC, yC), respectively. The sides of the triangle are the line segments AB, BC, and CA.A line passing through two points (x1, y1) and (x2, y2) can be considered to be the set of points (x,y) satisfying the equation

f(x,y) = 0
where f(x,y) is given as
f(x,y) = (x - x1) (y2 - y1) - (y - y1) (x2 - x1)

One of the interesting things about that f(x,y) is that we can use it to determine which "side" of the line an abitrary point (x,y) is on:

If f(x,y) = 0, the point is exactly on the line.

All points for which f(x,y) > 0 are on one side of the line, and All points for which f(x,y) < 0 are on the other side So the problem of determining whether a point (x,y) is on the inside of a trangle can be checking the sign of f(x,y) for each of the three lines making up the triangle.

A complicating factor is that we don't know, for any given triangle, whether those three signs should be all positive, all negative, or some mixture of the two.

The centroid of a triangle can be computed as the "average" of the x and y coordinates of the vertices:

xcen = (xA + xB + xC)/3
ycen = (yA + yB + yC)/3

This point (xcen, ycen) is definitely inside the trangle (unless the triangle is "degenerate" and has no interior points).

The problem of determining whether (x,y) is on the inside of a triangle can therefore be resolved by checking to see if it is on the same side of each of the trangle's line segments as (xcen, ycen).

I want to fill in the missing bodies for the functions eval and areOnSameSideOf, which manipulate line segments. I think calling eval from within areOnSameSideOf will simplify the implementation of the latter.

Code:
#include <iostream>
using namespace std;
/**
* 2D Cartesian coordinates
*/
struct Point {
double x;
double y;

[code]...

View 1 Replies View Related

C++ ::  permutation For Two Different Lists

Nov 7, 2013

I got a permutation question, I got two different std::list:

list<string> slist;
slist.push_back("str111");
slist.push_back("str222");
slist.push_back("str333");

list<int> ilist;
ilist.push_back(100);
ilist.push_back(200);

I need the permutation for both two lists, the result should be like this:

#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
template <typename value_t>
void dump_list(const list<value_t>& lst) {

[Code] ....

See, there are two do while loop, if I need a permutation with more than two lists, there'll be more and more do-while loops, that's make code looks ugly, I wonder if stl has some tricky way that can do this with just one next_permutation.

View 5 Replies View Related

C++ :: Linked Lists - Trying To Revive

Dec 27, 2013

I'm trying to set up a simple implementation of a double linked list. I can't make it fly.

Code:
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

[Code] ...

I seem to create a root vertex, but I can't establish if I connect sub nodes to my list.

View 13 Replies View Related

C :: Merging Two Linked Lists?

Mar 6, 2015

I am merging two linked list but the output of the program is not printing insert

Code:
typedef struct Merge
{
int info;

[Code].....

View 1 Replies View Related

C :: Dynamic Linked Lists

Oct 14, 2013

In our homework assignment it states to, "write a set of dynamic linked lists" and so on. Now, the problem I'm confusing myself is at the storage inside of each node. To my understanding, each node contains the prev and next nodes, but also a pointer to the data, in this case being a string. He has asked us to manage these strings as rows of chars such as

char[0] = c // first node being addressed here
char[1] = a
char[2] = t
char[3] =
char[4] = d // second node starting here
char[5] = o
char[6] = g
char[7] =

I have written my code where each node is holding a string, not separated as shown above... my question is to how you can build your doubly linked list where each node is being address a set of chars.

View 1 Replies View Related

C++ :: Nodes In Linked Lists?

Feb 26, 2015

I created a bunch of nodes and I made each one before one another. Im having trouble adding another node to the last one.

#include <iostream>
using namespace std;
struct nodeType{
int info;
nodeType *link;
};
void printList(nodeType *head) {
nodeType *current = head;

[code]....

The node with the value of 400 is the node that has to be last.. How would that work?

View 3 Replies View Related

C/C++ :: Working With Linked Lists?

May 11, 2014

I'm trying to do is let the user type in something like A654321 (note: these are ALL the characters, i.e. 'A', '6', '5', '4', etc..) Then I just want to display that current number back to them and I am getting some weird pointer memory allocation error..

#include<iostream>
using namespace std;
//To rename data-type "int" or integer to "element" (Both are equivalent)..
typedef int element;
//To declare an appropriate SENTINEL.
char const SENTINEL = '#';

[code]....

It seems like the first part that it bugs out at is in my Clean(); function..

Unhandled exception at 0x01383FBB in VegMe.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0.

It doesn't like head = head->next; ?Also, ignore the ReverseList(); function, it is not being used as of now.

View 7 Replies View Related

C/C++ :: How To Get Rid Of Lists And Vectors In Program

Apr 16, 2015

I want to get ride off lists and vectors in this program i also don't want to use classes, just want to use strings functions and structures...

#include <iostream>
#include <string>
#include <list>
using namespace std;
struct contact {
string name;
int studentiD;

[Code] ....

View 1 Replies View Related

C++ :: Program To Sort Lists?

Aug 12, 2014

What I want to create is a program that sorts through a huge list (millions of lines).

I want it to get rid of any line that contains a word that isn't in an English dictionary.

Example list:

00sdfdsf
ahdadsg
angel
ksjflsjdf
green
green000
carrot

and it would go through millions like that, giving me only:

angel
green
carrot

as my new list.

How could I go about this? What programs would I need? And at the very least how can I remove unwanted things like numbers, double letters, underscores etc.?

View 3 Replies View Related

C++ :: Traversing Array Of Lists Of Objects?

Nov 13, 2013

I am working on building a graph of a maze problem using an adjacency list and my own custom class Node.

Each Node has a vNum and jumpAmount integer variable, the vNum is the unique key.

If I have an array of lists of Node objects declared by: Code: forward_list<Node> adjacencyList[10] I skip the 0 row and only use 1-9. It makes more sense logically for my program and Im not worried about wasted memory at this point.

How could I go about traversing and outputting member variables for all the Nodes in each list in my array?

Say my code builds the following adjacency list:

Code:
1 -> { 2, 3, 4, 7 }
2 -> { 1, 3, 5 }
3 -> { 1, 2, 6 }
4 -> { 1, 5, 6, 7 }
5 -> { 2, 4, 8 }
6 -> { 3, 4 }
7 -> { 1, 4, 8 }
8 -> { 5, 7, 9}
9 -> { 8 }

where the values in brackets are the nodes that have an edge with the ith row node. Had to put it in code tags for the thread to be allowed to post.

I am using the forward_list library for my list functions and this is where my problem arises. The cplusplus.com - The C++ Resources Network website iterates through the list using:

Code:
for ( auto it = mylist.begin(); it != mylist.end(); ++it )
std::cout << ' ' << *it;

Obviously this works for ints, doubles, etc, but not objects with member variables. My attempt to replicate this code for my problem looks like:

Code:
for( int i = 1; i < 10; ++i ) {
cout << "Node " << i << " -> { ";
for( Vertex it = adjList[i].begin(); it != adjList[i].end(); ++it )
{
cout << it.getVNum() << ", ";
}}

I have to come up with user defined conversions for this to work and I have never done such a thing. Is there a way to go about doing this to avoid user defined conversions, because if there isnt I feel like attempting to do this specific problem might be a little too difficult for someone who hasnt defined any custom conversions.

Potentially, I could write my own List class and have a next pointer member variable that points to the next object in the list and use that to use a dot reference to a get function to display member variables. This is how I learned linked lists back in my Data Structures class. However I am trying to avoid that for the time being, as that would be a lot more code to implement rather than just figuring out how to use the forward_list library.

View 4 Replies View Related

C# :: Finding The Size Of Multiple Lists

Sep 21, 2013

I am writing a Windows Form program, and currently it has 3 Lists. I need to loop through all three, and use each possible combination, so am using three nested for loops.

I found that if the outer loop had less elements than one of the inner loops/lists, some were missed off, as I need to save all the possible combinations of list a + b + c.

This is what I wrote:

Code:
public int CalculateOrderToProcessLists()//for three lists
{
int order = 0;
if (sListOne.Count() > sListTwo.Count() && sListTwo.Count() > sListThree.Count())
{
order = 123;

[Code ....

My problem is I would like to be able to have 4 (or more if possible) lists, and to calculate what order to process the lists will be exponentially more complex.

Any better way of comparing the sizes of the lists, so that I can use the nested loops of say 4 lists, but being able to use N number of lists would be awesome.

View 2 Replies View Related

C :: 3D Array Of Pointers To Linked Lists

Aug 8, 2013

I am having some trouble getting a 3d array of pointers to link up with a linked list for each of the array elements. the 3d array of pointers is declared like this:

Code:

struct particle *cell[MAXCELLS][MAXCELLS][MAXCELLS]; and there are linked lists declared like this:
Code: struct particle { /* structure for particles */
double sw[3]; /* square well components */
double hs[3]; /* hard sphere components */
double u[3]; /* unit vector for rotations */
struct particle *link;
};

I want to get the array pointers 'cell[x][y][z]' to point to the first observed particle in a function next to main, something like this:

Code:

void generate_list(){
int i,j,k,l;
/* determine the number of cells to decompose the simulation box in each of x, y and z directions*/
int(cells_x) = floor(boxX/cell_size);
int(cells_y) = floor(boxY/cell_size);
int(cells_z) = floor(boxZ/cell_size);
/* initialise the array of pointers to NULL */
for (j=0;j<cells_x;j++){

[Code]...

I am getting a pointer type cast error when I compile "assignment from incompatible pointer type",

View 6 Replies View Related

C :: Reading A File To Linked Lists?

Jun 20, 2013

I have to write a program that reads from a text file, which contains a list of stock hourly prices and the company names. Something like this:

78.52 82.56 75.10 71.97 Water Company
22.40 25.68 21.37 22.96 Mega Shipping Inc

Each company data will be kept in a structure that contains: a pointer for the name, an array of the prices, and the average price for the day. The structures will be kept in a linked list. Each node structure will contain a pointer to one company data, and a pointer to the next node structure.This is all I have so far..

Code:

typedef struct {
char *companyName;
double hourlyPrices[NUM_PRICES];
double avgPrice;
} COMPANYDATA;

}

[code]...

We have to sort the nodes alphabetically. My question is, how do I read the data from the file one line at a time, and insert them alphabetically one by one?

View 7 Replies View Related

C++ :: Compare Single Value With A Value From Linked Lists

May 2, 2013

I'm trying to compare a single value with a value from my Linked list and if they are same, I want to add the value from the list to new list. In other words I want to create a new List with values with the first one. Here is the code that I made, but it's not working.

This is the code with which I search in the first list for a node with a value. In the main() function I have A.find_city(), so it can start from the start_pointer from the first list:

void List::find_city() {
List *temp1;
int b = 0;
char city[20];
cout << "Enter city: ";
cin >> city;
temp1 = start_ptr;

[Code] ....

This is the code with which I add a node to the new list:

void List::in(List *temp1) {
List *temp2;
if(start_ptr == NULL)
start_ptr = temp1;

[Code] ....

View 9 Replies View Related

C++ :: Stack Implementation Of Linked Lists

Jun 7, 2014

I have this code that I need to memorize for my final. Memorizing code is easy for me, but I'm trying pretty hard to fundamentally understand the functions, and what they are doing (even using pen and paper, to draw and trace).For example, in the push function below, I understand everything, except why I'm setting ptr = p. I feel like p should be equal to NULL, then the next node I push should be equal to p, etc.

Stack & Stack::push(double x)
{
Node * p = NULL;
try
{
p = new Node;
}

[code].....

Also, are LL Queues that hard to implement once you can do them w/stacks - That will probably be something I have to code for my final, as well. Below is the full code for my Stack class.

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
class Stack
}

[code]....

View 1 Replies View Related

C++ :: Counting Of Elements In A List Of Lists

May 1, 2013

I have a problem like this: I do not know how to count the number of elements in a list of lists. I have the following list of list.

#define VAR(V, init) __typeof(init) V=(init)
#define FOR_EACH(I,C) for(VAR(I, (C).begin()), ite = (C).end();
(I) != ite;
++(I))

std::vector<std::vector<GLdouble> > contours;

[Code] ....

I do not know how to write the part indicated in Bold that represents the number of elements of contour. As seen from the code used for the tesselation OpenGL.

View 3 Replies View Related

C++ :: Templates And Ordered Linked Lists

Feb 10, 2014

A static method named readFromFile that takes a C-string as the first parameter, and an orderedLinkedList<MemberDO> object as the second parameter. The first argument is the filename that contains data for existing members. This method should read the data for each individual member from the input file (one line of data per member), create a new MemberDO object, and insert this object into the linked list specified in the second argument.

How do I take the second parameter in, do I need to create the Linked List first? Here is the code I have so far

#include<iostream>
#include<string>
#include <fstream>
using namespace std;

class MemberDO {

[Code] ....

What to do with the readFromFile static method?

View 1 Replies View Related

C++ :: Dijkstra Algorithm - Adjacency Lists

Feb 28, 2014

So I have been trying to implement the Dijkstra Algorithm for shortest path in a directed graph using adjacency lists, but for I don't know what reason, it doesn't print out the results (prints the minimum distance as 0 to all nodes).

The code I wrote is:

#include <fstream>
#include <functional>
#include <climits>
#include <vector>
#include <queue>
#include <list>
using namespace std;

struct node {
int vertex;
int weight;

[Code] ....

The input data was:
5 7
1 2 10
1 3 2
1 5 100
2 4 3
3 2 5
4 3 15
4 5 5

It means there are 5 nodes, 7 arcs (directed edges), and the arcs exist from node 1 to 2 with the cost of 10, from 1 to 3 with the cost of 2, and so on.

However, the output is wrong. Where the program might fail. I took the main idea from here: [URL] ....

(At the end it gives the idea for Dijkstra's Algorithm using a priority_queue).

View 3 Replies View Related

C++ :: Can Compare vectors With Linked Lists?

Jan 31, 2014

Can we compare vectors with linked lists?

View 4 Replies View Related

C++ :: Merge Two Linked Lists Without Sort

Feb 19, 2013

i write code that's merge two linked list without sort ....

node * merage (node * list1, node * list2) {
// check witch list is empty
if (list1 == NULL) return list2;
if (list2 == NULL) return list1;
if ( list1 == NULL && list2 == NULL ) return NULL;

[Code].....

View 1 Replies View Related

C++ :: Merge Sort And Linked Lists

Mar 15, 2014

I am getting an error trying to convert from nodeType<Type> to nodeType<Type>* in my recursiveSort function and why this is happening.

#ifndef H_linkedListIterator
#define H_linkedListIterator
#include <iostream>
template <class Type>
struct nodeType {
Type info;

[Code] ....

View 7 Replies View Related

C++ :: Searching For Objects In Linked Lists

Jun 18, 2013

So I have a Class named Subject, wich I used linked list to keep the objects. Now I have another Class called Tests which I should register a test by the Subject class, so I made a search like this:

List obj; //it's the object to access the List class, which manipulates the
//nodes from Subject.

obj.currentPtr=obj.firstPtr;
while (obj.currentPtr!=NULL) {
if(obj.currentPtr->nameSubject==value) //searching if there's a
return obj.currentPtr; //name equal to provided
obj.currentPtr=obj.currentPtr->nextPtr;
}
return 0;

I've made a similar process for Subject. But in this when I access the firstPtr, it's shown to be 0, once I have already the list of Subject and it should not be zero. What's wrong?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved