I'm taking a programming class and currently we're doing data structures. Today, we discussed how to save square matrices column-wise with data structures. The teacher said that after the first few steps where you declare the structure, allocate the matrix, free it and get the dimension (which mostly make sense to me I think), you have to "get" and "set" the matrix by putting in something like
Code: void setMatrixEntry(Matrix* A, int i, int j, double Aij) { A->entries[i+j*A->m] = Aij; }
Osgood,Marcus 298542123 CHM FR mosgood@whatever.edu Cronk,Melissa 873489021 BIO SR mcronk@whatever.edu Pry,Seth 349908431 MTH SO spry@whatever.edu Langlais,Susan 783323545 ME SR slanglais@whatever.edu Davis,Nicole 987543345 PHY FR ndavis@whatever.edu
It's supposed to split it up into name, ID number, major, year, and email. The file reads it without any errors, and assigns name to the first part of the structure. However, ID gets assigned the ID, major, year, and email. Then Major gets assigned major, year, and email. Year gets assigned year and email, while email just gets assigned email. I don't know if it has something to do with the loop. For example, this is what I get what I print just the name and the ID.
Cronk,Melissa 873489021BIOSRmcronk@whatever.edu
Pry,Seth 349908431MTHSOspry@whatever.edu
Langlais,Susan 783323545ME
Davis,Nicole 987543345 PHYFRndavis@whatever.edu
Anyway. This is my function code for reading the array. I have it printing the ID number just to see if I can catch the errors earlier:
I need an explanation of what linked lists are. How the nodes are been defined and used, especially in an object oriented programming. With a code example.
I want to have input data stored in a database. All information entered is to be stored under a single block. That way whenever I want to recover that information all I have to do is point to that block. Think of it like this. I want a large square block that can hold certain information. Inside of that large block are a finite amount of smaller blocks in which the user entered information about a single subject. Lets say block 1 has a name, address, and phone number. The second block will have the same TYPE of information, but different values as entered by the user. I.E:
BLOCK 1: Name 1, Address 1, Phone 1 BLOCK 2: Name 2, Address 2, Phone 2 etc.
The large block contains all of the smaller blocks, we will name the large block "Address Book" ... How would I implement that? Of course it would be just a simple console program that would erase all information when the program shut down, but I've been trying to figure out how to do it, but just can't seem to grasp a good notion of how to do it. What would be the best way to do that? Structures? How would I make it dynamic so that I wouldn't have to define every block, so that it would be added on the fly when someone inputs new information.
We're writing a program in class using data structures and arrays and I'm stuck on writing a loop to find the students' highest test score. I only return the first student's ID, test score, and grade. For some reason unknown to me I'm not actually looping through all 12 or so records.
Code:
#include <stdio.h> #define MAX_ENTRIES 50 struct records { //declare my student records structure int ID; //the student's ID number int test_score; //the student's test score char grade; //the student's letter grade of aforementioned test score };
So this makes an output of the head (a square), and the leg (rectangle. How do I make my points into a data structure in the shortest yet simplest way possible?
I am trying to read the information from a .bmp file into my program while dynamically allocating memory for all of it. So I defined the structures for the headers and for a pixel, and then I have to read each pixel into a multi-dimensional array of pixels. I am completely new to structures, and definitely new to pointers combined with structures. I will have to use a filter with the information later, but right now I just want to read everything in correctly. The array of pixels will be two-dimensional -- the width by the height of the image, I guess.
Why certain projects always roll their own data structures/utililiy classes rather than using the C++ standard libraries? such as linked lists and queues? Is there a particular reason for this?
The program use a circular linked list and data structures to store the tasks.
- Every task should include a task name, a name for the person assigned to it, and the deadline for the task. - Variables should be dynamic and their sizes should be determined at runtime based on the length of user input. - You should implement the following functions (with appropriate arguments and return types) for your structure: add(), remove(), search(), and list(). - The add()function should add tasks alphabetically by task name. You do not need to implement any file operations. - The search() function should be able search for a task by the task assignee name or the task name. - The list() function should print records to the screen in the order they appear in the circular linked list. - You should successfully deallocate all of the allocated memory before termination of your program.
I am trying to read from a data file that has input as :
12.0, 11, 123 14.0, 12.1, 3
And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.
Code: #include <stdio.h> #include <stdlib.h> #define MAX_INPUT 1000 int n =0; int i = 0; typedef struct { double x[MAX_INPUT];
[Code] .....
The program when run gives the following output:
Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c ProjectB.c: In function "main": ProjectB.c:59: error: incompatible type for argument 1 of "print_array"
I am writing a employee payroll program using structures. My program is running but its only showing some of the data.
HERES MY CODE
Code: #include <iostream> #include <cstdio> #include <fstream> #include <string> #include <iomanip> #include <cstring> using namespace std; const int SZ = 20; // size of arrays to hold scores struct payrollStruct {
[Code] ....
And it doesn't show anything from txt file
Code: 40.0 10.00 A1234 Jane Adams 50.0 10.00 L8765 Mary Lincoln 25.5 10.85 W7654 Martha Washington 52.0 15.75 A9876 John Adams 45.0 25.00 W1235 George Washington
I have a program that stores health information the user inputs, one person at a time. The program works perfectly with the exception of storing the data...I need to open a file and read what health data it has in it already, if any, but store the new changes, and appended data to the array of structures, to the data in memory. All of the information is only saved back in the file once the program terminates. I'm not sure how to go about doing this, so I am also not sure what to put in the function for "Save and Exit" that the user can choose in order to exit the program.
I would like to modify the composition of this struct, so that I can create a special data structure by
vector<stest*> data_test; for(int i = 0; i < 10; i++) data_test.push_Back(new stest);
within this structure, I have: only one na and one nb, but ten groups of combination of va, vb, vc, vd that I can access by pointer, which means na, nb are independent but still inside of the structure.
I'm currently having the following data structure:
typedef struct { int a; int b; } S; <vector <vector<S> > v;
Now I also have different pointers that can be set in connection with one instance of the above shown vector. Therefore I was attempting to work with a map:
map<p*, <vector<vector <S> >, vector<sI> > m;
However, it seems like it doesn't work that way. Therefore I tried the following:
I want to know this because if I happen to want to use a lot of insertions and deletions then it is more efficient to make use of Linked List instead of Dynamic Array.
While, if I happen to want to just access random parts of the Array, then Dynamic would be more efficient.
I want to make a 2D game using SDL engine and I need to check whether or not an object is colliding with a list of other objects. (because there would be more then one objects on the map.)
Since I would simply be accessing each object sequentially to check whether or not the object is colliding with another the object in question, and since any of those objects could "die" and be deleted at any time, it makes more sense to use Linked List then a Dynamic Array.
i j x y w h w*h 0 0 0 0 9 11 99 1 0 0 11 9 10 90 2 0 0 21 9 11 99 0 1 9 0 8 12 96 1 1 9 12 8 7 56 2 1 9 19 8 6 48
[Code]...
Code:
struct data { //Here /*! horizontal position */ int x; /*! vertical position */ int y; /*! width */ int w; /
[Code]...
data and then i have an array /*! it contain group_id of each data line*/ int group_id[16]={0,0,0,0,3,3,1,1,1,3,3,2,2,2,2,1}; I never worked with 2D array before. My problem is that i want to create a 2D array of that data for example if i write data[j][i].. It will give me the reference/value of all data lines that belongs to j column, and same with group_id[j][i]. I don't know how i can store these structure vaules in this like 2D array.
Write a program that uses a structure named CorpData to store the following information on a company division.
Division Name(North, South, East, Or West) First quarter sales Second quarter sales Third quarter sales Fourth quarter sales Total annual sales Average quarter sales
Include a constructor that allows the division name and four quarterly sales amounts to be specified at the time a CorpData variable is created.
The program should create four variables of this structure, each representing one of the following corporate divisions: North, South, East and West. Each variable should be passed in turn to a function that calculates and stores the total annual sales and average sales for that division.
Once this has been done for each division, each variable should be passed in turn to a function that displays the division name, total sales, and average sales.
To check if a set B is a subset of A or not. Which data structure to be used to store set A for quicker response(linked list/hash map)? What if I want to check intersection also?