I am wondering if a struct is like an object or is an object. For example a struct: struct Books { public string title; public string author; public string subject; public int book_id; }; Defining this struct: public class testStructure { public static void Main(string[] args) { Books Book1; /* Declare Book1 of type Book */ Books Book2; /* Declare Book2 of type Book */ /* book 1 specification */ Book1.title = "C Programming"; Book1.author = "Nuha Ali"; Book1.subject = "C Programming Tutorial"; Book1.book_id = 6495407; /* book 2 specification */ Book2.title = "Telecom Billing"; Book2.author = "Zara Ali"; Book2.subject …

Member Avatar
Member Avatar
+0 forum 1

{file has 1000 lines that look like these 114680858 19670607 Matilda Vincent MI 114930037 19471024 Desdemona Hanover ID 115550206 19790110 Xanadu Perlman ND 116520629 19630921 Alexander Hall SD 117050976 19301016 David Lamprey GA 119610646 19650202 Thomas Porlock IL 120330928 19621126 Cary Cartman NC struct employees { int ss_number;//social security int dob;//date of birth YYYY/MM/DD Ex.) 19870314=1987/03/14 string f_name; string l_name; string state; //state of residence }; void read_file()//read file into array of 1000 structs { ifstream data("/home/www/class/een118/labs/database1.txt"); employees array[1000] if(!data.fail()) { int i; for(int i=0;i<1000;i++) { data>>array[i].ss_number >>array[i].dob >>array[i].f_name >>array[i].l_name >>array[i].state; } for(int i=0;i<1000;i++) { cout<<array[i].ss_number>>" "<<array[i].dob>>" "<<array[i].f_name>>" "<< array[i].l_name>>" …

Member Avatar
Member Avatar
+0 forum 1

I'm totally new to programming and taking an intro class. When i prompt the user for a state code the program just exits, nothing in my book really goes over this and all im given is crappy youtube videos for reference. Any help is greatly appreciated. #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 2 // initially to test kept it to SIZE 2 typedef struct { char firstName[30]; char lastName[30]; char street[35]; char city[20]; char state[3]; int zip; char phone[15]; int accountId; } Customer; Customer getCustInfo(int a ) { Customer cust; char firstName2[30]; printf(" Enter Data for Customer %d\n", …

Member Avatar
Member Avatar
+0 forum 3

Hello everyone, I'm trying to implement qsort on a struct with the double as a pivot: typedef struct{ char sequence[9]; int occurance; double prob; }tuple; ...... int compare (const void *x, const void *y){ if (x < y) return -1; if (x > y) return 1; else return 0; } ... qsort(x,k,sizeof(tuple),compare); Now I was trying to access members only to find that it doesn't work. int compare (const void *x, const void *y){ if (x.prob < y.prob) return -1; if (x.prob > y.prob) return 1; else return 0; } error: request for member ‘prob’ in something not a structure …

Member Avatar
Member Avatar
+0 forum 2

I'm trying to read information from a text file and populate an array of structs using a pointer. I keep getting an error and I'm not sure how to fix it. Any help, comments, or tips are greatly appreciated! Thanks in advance for your time and help! error: request for member 'budget_num'in 'ptr', which is of non-class type 'budget*' struct budget { int budget_num; string name; float budget_value; }; //Declare file streams ifstream inFile; ofstream outFile; int main() { //Declare variables budget company[15]; budget *ptr; //string MyString = ""; ptr = &company[0]; //Open inFile inFile.open("ledger.dat"); while(!inFile) { cout << "Error …

Member Avatar
Member Avatar
+0 forum 6

Hi all, Having a little trouble with assigning values to an array within a C struct. Unfortunately i cannot assign a size to the array as i am reading values to an array to be stored, and the size is relative to the other values in the struct passed to createGeo(); the function. The issue here is the float *coords - which i want to be filled with values in the createGeo() function. typedef struct geom{ float dimen[3];//width, height, length int totalQuads; float *coords; GLubyte indices[]; }geo; geo Base; void createGeo(geo inst); int main(int argc, char *argv[]) { Base.dimen[0] = …

Member Avatar
Member Avatar
+0 forum 4

Hello all. I am having difficulty getting my program to output data correctly. I have a class member function that is supposed to return the value of a specific member of a struct element based on identification with its (the struct element's) other members. [code] float MatrixType::valueAt(int i, int j) const { // code to return the float value at // significant location row i col j if(i == matrix[length].row && j == matrix[length].col) return matrix[length].value; // checks to match up row and col to find correct value else return 0.0; } // end accessor valueAt[/CODE] The matrix[] array is …

Member Avatar
Member Avatar
+0 forum 6

I have been having trouble developing a function that frees all of the memory associated with structs of a linked list. Im not asking for a clear cut answer, just an idea or a function that can aid. F.Y.I. the linked list contains a head struct and a tail struct to identify the Here's some code that might spark some thought: [CODE]void deleteAllStructs(void){ struct structTypeName listingPtr; do{ for(listingPtr=gHead;listingPtr->next!=NULL;listingPtr=listingPtr->next) ; listingPtr = NULL; while(gHead!=NULL); }[/CODE]

Member Avatar
Member Avatar
+0 forum 6

I'm writing a program that takes records(first and last name,id and mark), reads them from a file and inserts the information in StudentRecord structures. For some reason,when I go to list the information, the first and last name strings in each structures are all the same. The first and last names are the last ones loaded from the file. I tried printing the members right after they're assigned and it's the right name but when I call the list function the names aren't right but the ID and mark data is correct. For the list function all I do at …

Member Avatar
Member Avatar
+0 forum 10

Hello guys, I've tried searching the internet on how to cout a struct in an array via a binary search, but with no success. I've only learned how to do a linear search and I sort of understand how to do a binary search but: how do I cout the found student record/ results of the search? Any help at all would awesome! I'm not so good with making functions but, my current whole code: [CODE]#include <iostream> #include <iomanip> #include <string> using namespace std; void clrscr() { system("cls"); } void pause() { system("echo.");system("echo.");system("pause"); } void displayMenu(string msg) { clrscr(); cout …

Member Avatar
Member Avatar
+0 forum 22

hi all and thanks for reading. Personally i thought i wouldnt be in the frame of putting up one of my assignments, as i can see where an opinion might be formed, over me trying to pull as fast one and get someone to code this for me etcetc etc..... But can someone tell me if im right in thinking it means...either: 1. create an array 2. create a struct 3. create *ptr array and one of the above All to include user input and then to ba able to be saved appened and written to (using "r+a" syntax, at …

Member Avatar
Member Avatar
+0 forum 1

I need to read data from a file into an array of structs. The info is arranged in the file like so... Spear of Extreme Whaling January 1851 Captain Ahab Each member of the array has a name, month, year, and first and last name of creator. This is the beginning of my code: [CODE]#include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; struct artifact { string name; string month; int year; string fname; string lname; }; int main() { artifact allInfo[31]; char menu; char yn; int j=0; string name; string filename; string yearTemp; ifstream inFile; ofstream outFile; cout<<"Enter a file name: …

Member Avatar
Member Avatar
+0 forum 1

Hello everyone. I'm coming to you again because you all seem to be much more on the spot answering my questions than my professor. The long story short, we are being introduced to structs in my c++ class, and for the first assignment we are to do a simple Student GPA struct and then print it out to the screen. I will copy and paste the email I just sent my professor to save time, but what I wrote above should fill in any gaps from that email. -------------------------------------------------- I am working on the GPA assignment. I am just doing …

Member Avatar
Member Avatar
+0 forum 5

Hi - i have been trying to create a linked list in C using structs and there are a couple of things i am stuck with how to declare the node front and back and do i keep repeating myself? Also in the function push back how can i use the linked list i created ? [CODE]#include <stdlib.h> typedef struct node { int data; struct node* next; struct node* prev; }; typedef struct llist { struct node* front; struct node* back; }llist; llist* linked_list_create() { llist* aLL = malloc(sizeof(llist)); aLL->front = 0; aLL->back = 0; return aLL; } int linked_list_push_back(llist* …

Member Avatar
Member Avatar
+0 forum 4

Hello everyone. I've been trying to implement a linked list in C++. I found this implementation on the web, where they created a struct for the list's nodes. When trying to add a new node to the list, I get this error: [B]List.C: In member function `bool Linked::addNode(Point)': List.C:23: error: no matching function for call to `Linked::node::node()' List.H:35: note: candidates are: Linked::node::node(const Linked::node&)[/B] And here's my Code, and thank you very much.. :) [B]List.H[/B] [CODE]#ifndef _AUXILIARY_H_ #define _AUXILIARY_H_ #include <string.h> #include <math.h> class Linked { public: // Constructor: initializes a set of nodes Linked(); // Linked methods bool addNode(Point p); …

Member Avatar
Member Avatar
+0 forum 5

I have to load two arrays, merge the two arrays into a third array, then create a control break report on name while outputting the most frequent style, then sort the array by style and to a control break on style. Can someone look at my code and see if they can see what I am doing wrong. [CODE]#include <iostream> #include <string> #include <fstream> using namespace std; struct salesTran{ string name; string style; double price; double quantity; }; void MERGE(salesTran A[],int count1,salesTran B[],int count2,salesTran C[],int size, salesTran Temp[]){ for (int i=0; i<count1; i++){ C[i]=B[i];} int j=count1; for (int f=0; f<size; …

Member Avatar
Member Avatar
+0 forum 4

I really have no idea where to start. Please only respond if you actually want to help. Not to name names, but [B]some [/B]people on here are just rude. Here is the assignment and any advice will be [B]greatly [/B]appreciated! 1. Write a program that allows the user to enter a series of positive floating-point numbers. 2. Store the numbers in a linked list. 3. Allow the user to enter numbers until a negative number is entered. (terminate when a negative # is entered). 4. Next, transverse the list to total the numbers entered, number of nodes, and average to …

Member Avatar
Member Avatar
-2 forum 5

[CODE] while(temp != NULL) { if(temp->info.Name == cName) { temp->info.DiscountNumber = temp->info.DiscountNumber + 5; flag = true; } if(temp ->info.DiscountNumber > 25) { temp->info.DiscountNumber = 25; // prev->link = temp->link; // delete temp; //temp->link = first; // first = temp; } //cout<<"Discount is :" //<<temp->info.DiscountNumber //<<endl; prev = temp; temp = temp->link; } [/CODE] I am writing a program that will read data on customers from a file and grab names from a second file and add a 5% increase on the customer if their name is in the 2nd file. The current problem I am having is that I …

Member Avatar
Member Avatar
+0 forum 4

[CODE]<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="Player1" width="200" height="100"> <param name="URL" value="<s:property value="adFilePath"/>"> <param name="http://path_to_the_video"> <param name="AutoStart" value="0"> <param name="ShowControls" value="1"> <param name="ShowStatusBar" value="1"> <param name="ShowDisplay" value="1"> <param name="stretchToFit" value="1"> <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" width="200" height="100" src="<s:property value="adFilePath"/>" filename="<s:property value="adFilePath"/>" autostart="0" showcontrols="1" showstatusbar="1" showdisplay="0"> </embed> </object>[/CODE] Above code in the place file name i am using <s:property> of struts 2 this gives the ad file path, but player not working(It was working in firefox but not in ie). if any one already use player for struts 2 application plaz help me....... its very urgent.. Thnks, sriniavs

Member Avatar
+0 forum 0

Can someone tell me what wrong with this code i am supposed to create an array of struct of cars and then add 1 to the car sold then find the inventory value comprising of all car values this is my infile lexus IS 35000 10 bmw 740 90000 5 and this is my code [CODE] #include <iostream> #include <string> #include <fstream> using namespace std; struct carType { string make; string model; int cost; int numberOnHand; }; void init (carType cars[], int currentCarCounter); void print (carType cars[], int currentCarCounter, int Max_car_types); void addToInventory (carType cars[], int currentCarCounter); int inventoryValue(carType cars[], …

Member Avatar
Member Avatar
+0 forum 2

The End.