You should post the code either directly on DaniWeb (using code tags) or on something like http://codepad.org/ .
And your teacher was right - you shouldn't use goto :)
David
You should post the code either directly on DaniWeb (using code tags) or on something like http://codepad.org/ .
And your teacher was right - you shouldn't use goto :)
David
Ov course you don't, but many people here feel that vectors are the only solution to using arrays. They love suggesting things obviously beyond your level.
This is not beyond his level. There is no reason to learn arrays before vectors. Novices should learn vectors because they convey the same concept but are "easier" and THEN be told that if they want to get rid of the overhead they can access the memory directly using arrays.
You should look into the Qt library. Poke around for some tutorials. I also have some examples here:
http://programmingexamples.net/index.php?title=Qt
and a "crash course" here:
http://rpi.edu/~doriad/Talks/Qt_Introduction.pptx
David
Put them into an std::vector of std::string's and then std::sort() them:
http://programmingexamples.net/index.php?title=CPP/AlphebetizeString
You should be able to simplify this 230 lines down to about 20 relevant lines for us :)
Welcome to DaniWeb! We are all about learning here. No one really benefits if we just write code for you. What you should do is:
1) remove punctuation: http://programmingexamples.net/index.php?title=CPP/Strings/DetectPunctuationparse
2) parse the file on ' ' : http://programmingexamples.net/index.php?title=CPP/Strings/Split
3) put all of the words in a std::set and keep track of how many times the insert failed (i.e. the word was already in the set) using an std::map with key: word value: count
Once you try each of those steps, feel free to ask if you have any questions.
Good luck,
David
Welcome DaniWeb! A few suggestions:
1) Use code tags when posting code. It makes the code much easier for us to read.
2) Use real English words. I.e. "Please" instead of "Plz". It helps the community maintain a professional image.
3) You are outputting 'str' before assigning anything to it. Of course it will be garbage.
4) You should use std::string instead of char[].
Good luck,
David
I suggest you come up with a simple example problem, and then do the problem step by step by hand. Then step through the code with a debugger and ensure that it is doing every step the same as you did by hand. This will let you find the bug, then you just need to fix it!
You can do some cool tricks with stringstream:
http://programmingexamples.net/index.php?title=CPP/HexToInt
Why not? You just use the same array (it's values are now different). Post the loop if you still don't understand.
Yes. In that case you want to pass the vector by reference, and not return anything:
void yourFunction(std::vector<long double> &yourVector) // note the &
{
// modify yourVector
// don't return anything, the values have been modifying in the vector you have passed.
}
Then you call this with:
std::vector<long double> yourVector;
yourFunction(yourVector); // yourVector will be modified
David
Are you opposed to using a library? ImageMagick, ITK, VTK, VIL (from VXL), CImg, and OpenCV should all do the trick :)
You can't do this:
vector<long double> a;
a[0] = 1.0;
'a' hasn't been given any memory.
You need to do:
vector<long double> a(1); // give 'a' exactly one element
a[0] = 1.0;
or much better:
vector<long double> a;
a.push_back(1.0); // extend 'a' as needed
It is starting to seem like you are just trying to get this assignment done instead of learning c++ - I hope this is not the case!
That is fine, but you wont get the returned value.
Why are you passing a vector<long double> as a parameter?
The function should be defined like this:
std::vector<long double> IFS::yourFunction()
{
}
then you should call it with:
IFS yourClass;
std::vector<long double> returnedValue = yourClass.yourFunction();
Certainly:
std::vector<long double> IFS::yourFunction()
{
vector<long double> a;
return a;
}
The type before the function name is the return type:
std::vector<long double> yourFunction()
{
vector<long double> a;
return a;
}
Ok, you have multiple problems.
1) Those are not .o files. They are .cpp files.
2) At line 87 in diamond.cpp, you have
for (y = 1; y <= size - x; y++)
{
cout << " ";
}
cout << border;
}
That is an extra }, it should be just:
for (y = 1; y <= size - x; y++)
{
cout << " ";
}
(you also have the same problem again later)
3) You don't have header guards:
#ifndef DIAMOND_H
#define DIAMOND_H
// your header
#endif
4) The real problem you were asking about:
You are indeed missing definitions for those constructors. Adding this to diamond.cpp lets it compile and link properly:
Diamond::Diamond(int)
{
}
Diamond::Diamond(int, char)
{
}
Good luck,
David
What do you mean "How do I use c++ to do ..." - it is a language - once you know what you want to do, you have to figure out how to do it within the language. You'd probably want to have a CoffeeMachine class that has functions like "PourCup", "IsEmpty", etc.
Oh I see, I just saw the screenshot that looked like a standalone application and assumed it was a standalone application - but I guess it is, but generates a webpage. Also yuck, it's not open source :( When I start to find bugs they will never be fixed! haha. Also, I don't know if we have the budget to buy something like this - the free-er the better :)
Also, it doesn't look like it supports SQLite?
David
You probably declared it after you tried to use it. Can you send us a compilable example? Also, watch out for case sensitivity - 'Mystruct' vs 'MyStruct'.
Hi BanKuZ, welcome to DaniWeb!
Which operator would you like to use? Maybe you can also post your class structure, I'm not sure I followed what is going on from what you posted.
David
@rch1231, that doesn't seem to be web based?
@pritaeas, that is for MySQL. You were supposed to read my mind and know I was trying to use SQLite3 :)
Is this for a course assignment? I'm still not sure what you are trying to accomplish? The conditionals inside which you compute the 'tax' seem like a reasonable approach.
What are all of those cutoff* variables? Why wouldn't you just assign the calculations to 'tax' as was done originally?
There are lots of stand alone programs (sqlitespy, sqlitestudio, etc) that give you nice spread-sheet style access to tables:
but does anyone know of a web based way to do this?
Thanks,
David
Please also provide sorted_list_example.cpp. However, both files should not need to be longer than about 15 lines to demonstrate the problem :)
What is ACE? I suggest you ask the ACE people how to do this, as it is not standard c++.
Here is an example how concatenating STL strings:
http://programmingexamples.net/index.php?title=CPP/Strings/Concatenate
I finally got my navigation drop down menu working!
http://ewh.ieee.org/r1/schenectady/
I had been testing in Chrome, Firefox, and IE8. Before my celebration even really started, a user pointed out (correctly) that it doesn't work in IE7 :( The menus drop down on hover, but they aren't aligned, and you can't click on any of the menu items. Does anyone know why this would happen/how to fix it?
Thanks,
David
So it sounds like you've already narrowed it down to the shared_secret_key function. If you can give us a sample input, the desired output, and the current output to this function maybe someone will be able to spot the problem. That is, I bet you can reduce thes 180 lines to about 15 lines that demonstrate the problem.
David
Sure thing. Please mark the thread as "solved" if you're all set with this question.
David
The function returns void (i.e. nothing) so you can't output it. Simply do:
std::cout << a << " " << b << std::endl;
David
You did indeed use the tags properly :)
Method 1
struct MyStruct
{
int a,b;
}
MyStruct IFS::eval(int x, int y)
{
int a = ...
int b = ...
MyStruct mystruct;
mystruct.a = a;
mystruct.b = b;
return mystruct;
}
.....
Call with:
MyStruct result = IFS::eval(x,y);
Method 2:
void IFS::eval(int x, int y, int &a, int &b)
{
a = ...
b = ...
}
Call with:
int a, b;
IFS::eval(x,y,a,b);
I hope this helps!
David
Welcome to DaniWeb!
You could do two things.
1) Make a struct, fill the struct with the two values, and return it.
2) "Return" a and b by reference.
Also, please use code tags when posting code.
Good luck,
David
You will not find the source of a linker error anywhere in the code. It means you are not linking to the opengl libraries properly. Please send the actual error output. It would also help if you could make and send us the shortest program that you can that gives you this error.
Thanks, this is the answer to the original question (also posted previously by Kraai). I'll have to distill my other problems a bit more :)
The height in your html rule is set to 101%.
I've been told that this may be a good idea so that the scrollbar is always displayed no matter how long the content is. However, my question still remains that this page should actually have nothing to scroll (though it still does).
Your body element is positioned relatively and has a top style of 10%.
This is because I want some gray (the html background-color) to show above the blue (the body background-color). Is this not how I would achieve this?
Your div with a class of whitebox has a margin-top: 10px;
This is because I want some blue (the body background-color) to show above the white (the whitebox background-color). Is this not how I would achieve this?
You have a paragraph containing your logo. Paragraphs create a new line both before and after the paragraph element.
Should I make it a div instead? Surely that is not what is causing the page to be about 10% taller than the screen, right?
Ok, I've moved everything into http://ewh.ieee.org/r1/schenectady/New/style.css . The words of each button are centered, but the buttons are stretched across the whole page.
Any bright ideas?
The answer is, as you might expect, somewhat simple to understand, but harder to fix. First, you have set a width of 100% to the <ul>. You can't center something that's already the entire width of the containing element. There's nothing to center.
Did you mean set a width LESS than 100%? Or are you saying that by default its width is just equal to the width of the content, so by telling it to be width=100% of the page then it has room to move the content around that bigger space?
Your real problem, however, is that your dropdown.css stylesheet is clobbering your style.css stylesheet. To see what I mean, just remove the dropdown.css stylesheet and set your .menubar class to something like 60%. The result is not going to be pretty, but you'll at least see that now it tries to center.
Yep you're right - it is centered now (though indeed ugly). I'll have to look into what dropdown.css is doing and make it place nice with my style.css. I'll have to get back to you on this one.
1)
I use height: 101%, as well as margin-bottom: 1px, to always generate a vertical scroll bar on the browser page. That stops that annoying shift that happens when pages resize themselves. Using it is strictly a matter of preference.
Would the height of 101% not do that on its own (i.e. without the 1px bottom margin)?
2)
I created a menu class with a fixed pixel height:
.menubar
{
margin-left: auto;
margin-right: auto;
text-align:center;
width: 100%;
height: 100px;
}
and applied it to the ul:
<ul id="nav" class="dropdown dropdown-horizontal menubar">
and that sucker is STILL not centered!!!
3)
I added a margin-top: 10px;
to the whitebox class and it did not shift down to show some blue at the top as I would expect?
Ahhhh this is driving me a bit crazy!
David
Ok, I removed the rats nest - as far as I can tell everything is done from the css file now. Please see:
http://ewh.ieee.org/r1/schenectady/New/style.cxx
and the result:
http://ewh.ieee.org/r1/schenectady/New/
The only thing I have not taken your suggestions on are the ul and li elements, as these I have styled using the css files that I got with the javascript to make the menus (dropdown and dropdown-horizontal) (in the /css/dropdown folder).
Is something in there messing up the centering of the menu? (as you can see it is still not centered).
I had a bunch of margin statements that you have removed because I wanted to be able to see a little bit of blue above the white box. To this, would I just add a "margin-top:100px;" to the whitebox element?
One last thing - in your footer element:
div#footer {
position: absolute;
left: 0;
bottom: 0;
}
are "left", "bottom", etc referring to the position? I.e. would an equivalent statement be
div#footer {
position: absolute;
position-left: 0;
position-bottom: 0;
}
?
I really appreciate all of your help so far!
David
Also, in some things you have used a dot:
div.whitebox
while in others you have used a # :
div#footer
Is there a difference?
Thanks Jim! I'm in the process of moving everything to the css per your recommendation. A couple of questions in the mean time:
1) height: 101%; - is this a typo? Or do you use 101 for a reason?
2) "Also, you'll need a fixed pixel height." - do you just mean use px units? I am very hesitant to do anything like that as I won't know how it will appear on multiple resolutions (without lots of experimenting).
I changed the ul width to 100% and gave it a height of 10% (what should this have been)? It is still left justified!!
By "fixed width" - do you mean specified in pixels (as opposed to percentage of the parent container?)
I am absolutely not trying to do anything fancy (the auto width li tags as you suggest) - I'm happy to change to the easiest method of getting this thing centered and the <p> to start below it :)
Yea, <br/> would probably work, but I heard that it is not staying "pure" to separating content from display (which I'm trying to do for learning purposes only). The only reason I used 50% width was that apparently centering doesn't work unless you specify a width, but I wasn't sure what number to use.
All of this seems very awkward and confusing - surely I am doing something wrong? It seems like I'm trying to only simple/basic things, no?
I don't have that - it is commented:
html
{
height: 100%;
/*overflow: scroll;*/
}
So I thought it would be ok to just have the menu and the main text inside the "whitebox" div. Is that not ok? I thought I should only make a new div if I want to change the style? Since I am styling the <ul> and the <p> inside the whitebox div, I didn't see a reason to start a new div. Is this not correct?
David
On this page:
http://ewh.ieee.org/r1/schenectady/New/
it seems like the gray background object is larger than the screen - i.e. scroll bars appear even though the content is not long enough to warrant them. I have the following properties:
body
{
height: 100%;
}
html
{
height: 100%;
}
Shouldn't it be exactly the right size and therefore not need scrollbars?
Thanks,
David
I'll start a new thread for this - thanks for answering the original question :)
On this page:
http://ewh.ieee.org/r1/schenectady/New/
I have a <ul> element (the menu bar) followed by a <p> element (the main body text). Shouldn't the <p> be below the <ul> since it is a block element by default (instead of on the same line as it, as it is now)?
Thanks,
David