Can a struct contain other structs?
I would like to make a struct that holds an array of four other structs. Is this possible? What would the code look like?
The B-tree is of order 4, meaning that it can hold 4 pointers, and 3 keys.
The following is inserted: A G I Y
Since they can't all fit in one node, I know that the node will split. So I know there's going to be a root node with 2 child nodes after these things are inserted, but I don't know exactly what they'll look like.
ofstream f("test",app);
f.seekp(5,ios::beg);
f << "hello world";
f.close();
What I'm trying to do here is open a file that already has data in it, and then put "hello world" somewhere in the middle of the file. However, when I run my code, it overwrites the whole file. How can this code be fixed?
Let's say I have a text file that is 100 lines long. I want to only change what is in the 50th line.
One way to do it is open the file for input and open a new file for output. Use a for-loop to read in the first half of the file line by line and write to the second file line by line, then write what I want to change, and then write out the second half using a for-loop again. Finally, I rename the new file to overwrite the original file.
Is there another way besides this? A way to modify the contents in the middle of a file without touching the rest of the file and without writing everything out again?
If there is, then what's the code to do it?
Here is a simple header file for six different programs that used to work right, but then my files also include other files. This needs to get changed so that if the dependencies change the files that include those dependencies get updated.
all: load list show add delete btree
%: %.cpp
g++ $< -g -o $@
The following function writes a struct to a file.
int btwrite(short rrn, BTPAGE *page_ptr)
{
long addr;
addr = (long) rrn * (long) PAGESIZE + HEADERSIZE;
lseek(btfd, addr, 0);
return (write(btfd, page_ptr, PAGESIZE));
}
The following is the struct.
typedef struct {
short keycount; /* number of keys in page */
int key[MAXKEYS]; /* the actual keys */
int value[MAXKEYS]; /* the actual values */
short child[MAXKEYS+1]; /* ptrs to rrns of descendants */
} BTPAGE;
What would happen if I changed the struct to a class, would it still work the same?
If I added class functions, would the size it takes up on disk increase?
I want to copy a string into a char array, and not overrun the buffer.
So if I have a char array of size 5, then I want to copy a maximum of 5 bytes from a string into it.
what's the code to do that?
I want to write to a file without overwriting anything. It is a text file containing records. When I delete a specific record, I do not actually remove it from the file, I just put information in the header saying that it is deleted. How can I do this?
So far I've been using vi, but I'm wondering if there's something better to use in Linux. In Windows there's Visual C++, and I guess practically all C++ programmers in Windows use this these days. It has a lot of things in it to help the programmer. What about for Linux?
I know how to do extendible hashing on paper, but I don't know how it's possible for empty buckets to be created.
What would cause empty buckets to be created in extendible hashing? Can you show a simple example?
Instead of executable code all it does is create files that don't do anything, even if the files are made executable.
TARGETS = load list show add delete btree
all: $(TARGETS)
%: %.cpp
g++ $< -g -o $@ -MM -MF [email protected]
sed "s/$@\.o:/$@:/" [email protected] > [email protected]
-@rm [email protected]
DEPS=$(TARGETS:%=%.d)
-include $(DEPS)
On websites where you have to enter a user name and password, I notice that I can browse the site with one browser and it will know who I am no matter where I go on the site. But if I open a different browser it doesn't know who I am in that browser unless I log on in that browser.
After I log in to a website, does it store some kind of cookie in my browser, and every time I navigate to a different page on that site, it checks the cookie for my identity?
What would happen if I logged in, and then before browsing to a different page on the site, deleted the cookie?
When I try to compile my program the compiler complains about this line in a .h file that I #included.
ostream & Print (ostream & stream);
How can this be fixed?
If I declare a function like this:
string hash (char* key)
then any change I make to key will also change it's value when the function exits, correct?
I want to make a copy of it in the function so that I can safely change it without changing the original value.
I tried this, but it doesn't work.
string temp = key;
How can it be done?
Let's say there is a B-tree of order 8. This means it can have 8 pointers and 7 elements. Say the letters A through G are stored in this B-tree. So this B-tree is just a single node containing 7 elements.
Then you try to insert J into the tree. There's no room, so you have to split the node and create a new root node. Which element gets promoted up into the root node?
#include <iostream>
using namespace std;
typedef struct
{
char streetName[5];
} RECORD;
int main()
{
RECORD r;
cin >> r.streetName;
cout << r.streetName << endl;
}
When I run this program, if I enter in more than 5 characters, the output will show the whole string I entered. It does not truncate at 5 characters. Why is that?
How can I get this to work correctly?
I have a text file containing a number of records. Each record is stored on a single line that is 100 characters long.
Let's say I want to directly access the nth record. I could do it using a for loop, reading in n lines until I get to the record.
But how could I access it directly?
When a node in a B-tree is split, are keys from the original node duplicated in the new nodes? What's the purpose of doing this? Isn't this inefficient?
There is a .h file and a .cpp file with the same name but different extension.
If I want to use what's in the .cpp file, do I include the .h file or the .cpp file?
In my header file I'm getting the
error: ‘string’ has not been declared
error but at the top of the file I have #include <string>, so how can I be getting this error?