EDIT: deleted my explanations because I agree with Salem...also, could you try to be a little clearer with your question (I find it difficult to understand). And try some google searches...you can easily find an in-depth explanation of factorial, C++ i/o (reading from the console), etc...
n1337 29 Junior Poster in Training
n1337 29 Junior Poster in Training
Thanks!
I am trying to make a game based around beats of a song. I need my program to output every time the most prominent beat (not sure if right wording) occurs.
Sounds like you are looking more for volume than pitch.
Some ideas: you may want it to output everytime a beat exceeds a certain sound level (or pitch if you decide to use that instead). If not this, then you will likely need to specify a time period (for example, one bar length) for your program to search (however this works) to output...i.e. most prominent beat every bar. This way it will continue to output whatever it is you are outputting...
Goodluck though! Let me know whatever you figure out (I'd be interested in seeing your source code when your done).
n1337 29 Junior Poster in Training
Seems like an interesting project. I don't actually know anything about this myself, except that you might have to do some hardware interfacing (with the soundcard).
This book looks like it has a lot of material on the subject:
http://www.pearsonhighered.com/educator/academic/product/0,3110,0201419726,00.html
Other than that, all I can suggest is that you run some google searches to see what you can find.
Note: Hertz has to do with the frequency of the sound wave (i.e. pitch), I didn't know if you meant volume (decibel) spikes or changes in pitch...And you may have to do some research on how sound is stored digitally
n1337 29 Junior Poster in Training
while(current->name!=name) { previous=current; current=current->link; } current=current->link; previous=previous->link; delete previous; }
Can I see your list struct?
I think you are losing a pointer in your code though. Before you delete the specified node (the one you want to delete), you need to make sure that the previous node links to the node after the specified node. That is, you need to grab the specified node, then set previous->link equal to the node after the current (specified) node. Then you can delete the specified node...Make sure you don't have any pointers to it though.
Also, in your while loop, what if you never find the name of the node? (errors...) You should account for if this happens (i.e. check if your list becomes NULL and then exit)
Also, I don't think your if statement makes sense...In fact, I don't think you need it...
n1337 29 Junior Poster in Training
Order notation is just like a simplified mathematical expression. O(n), or order-n, is like saying that the runtime is "linear", or roughly proportional to n (which could be the length of a list, the depth of a tree, the number of characters in an input, etc).
We use order notation to give an idea of how efficient we are being with our code...If we wanted to be very precise, O(n) comes from a mathematical analysis of your program. For example, if you had the program:
#define n <whatever number>
int ctr = 0;
while (ctr < n);
{
ctr++;
}
we could analyze the code as follows:
We do some constant amount of work to declare the counter, say k (this is just some constant representing the amount of work in the preprocessing). Each pass through the loop, we do another constant amount of work, a (i.e. incrementing ctr). Clearly, we loop n times, and we do a work each time, so the loop gives us a*n work. Thus the program does a total amount of work equal to "a*n + k". We see that this resembles a linear function of one variable. As such, we can bound the running time of the program above by some other linear function, say m*n (especially for large n). Thus, we say that the program is order-n, or O(n), because the amount of "work" done is bounded above by some linear function of n.
You can analyze programs and …
n1337 29 Junior Poster in Training
It's just another poor example of teachers trying to get students to use recursion. In most cases the solution to the assignment they hand out would be much better suited to a loop, and the result is that kids know how to use recursion, but don't know when to use it. Theoretically, any recursion can be turned into a loop, but situations do exist out there where recursion actually can provide a simpler solution -- it's just somewhat difficult for teachers to create assignments which demonstrate that.
It is difficult to create assignments on recursion in a conventional course because generally recursive solutions are best suited to more advanced data structures (braun trees, directed graphs, etc) which are likely beyond the scope of a first programming course...so you end up learning recursion just for the sake of satisfying the curriculum.
The issue is of course, once you've learned looping, recursion is given to you as an afterthought, and you become so entrenched in looping iterations that thinking recursively is much more difficult, and seemingly pointless. The other thing is, I don't believe that any C++ compiler optimizes for structural or mutual recursion, only tail recursion for speed reasons (i.e. on a standard C++ compiler, structural/mutual recursion are slower and very memory inefficient...if you have ever played around with recursion then you've no doubt gotten a stack overflow error if you use C/C++).
But of course many patterns are recursive in nature...sequences and series and other mathematical patterns (think …
n1337 29 Junior Poster in Training
One Person did that for Me but the Logic the problem was he was doing the general case and was using the input Pa=100, Pb=100, K=1 and L=3 his output was 93.75%..
As per my question, input should be Pa=100,Pb=50,K=1,L=3 output should be 93.8%
Actually, I was not doing the general case, but only the first given case. I basically handed you the general case in my next post (where I constructed a tree diagram). And I did in fact use Pb = 50, NOT Pb = 100, in my first post. And my output of 93.75 is correct, notice that the given answer of 93.8 is simply 93.75 rounded to 1 decimal place.
And I apologize for not continuing to help, but I've done all the thinking I can for you...The only way I could make it any clearer is to write the code for you (and believe me, I don't have the time to do so), which is against the rules, and isn't really a learning experience for you. Goodluck though...
Nick Evan commented: well said +5
n1337 29 Junior Poster in Training
ummm you could try changing the function to have return type pointer to char...
i.e.
//in the Person class...
[B]char*[/B] personFind(char pid[]);
//...
[B]char*[/B] Person::personFind(char pid[])
{
//code goes here...
}
I am also worried that if you end up returning the name, you do not close the file...that is, your code never reaches the readFile.close() line (unless I'm missing something)...
n1337 29 Junior Poster in Training
I would assume a test client is simply a driver that tests the various levels of your program...i.e. creating a driver to test the different classes....
And you could propose tons of classes to be derived from CollegeStudent and Professor....there are pretty much no bounds, for example:
You could derive GraduateStudent and UndergraduateStudent from CollegeStudent, which encapsulate the years as a student, years left in the program, program itself, any previous schools attended, current school, etc etc.
You could derive various departments from the professor class, for example MathProfessor derived from Professor, which implements the subjects taught, years as a math prof, tenure, schools taught at, faculty association, etc etc.
Of course, some of these members might already be implemented in the Professor or CollegeStudent class, so you would instead make more specific members...
Really you could go on forever...basically deriving classes as they meet your needs. Essentially, deriving classes allows you to inherit certain properties (from the Person, Professor/CollegeStudent or other base classes), and expand upon others (by adding specifics in the new classes)...
hopefully that helps?
n1337 29 Junior Poster in Training
Again, be specific with the areas of difficulty...
An array of strings? My question is, suppose you had the array:
{ "me", "you", "us" }
Does the output need to be reversed like "us", "you", "me" (if so, just start at the last index and move backwards), or "su" "uoy" "em"...
Either way, you should be able to think about it...simple manipulation...
The problem requires you being able to write to a file (which you should understand, if not google search it...), and pass through an array...again, you should be able to handle this...but post back with your attempted code and specific areas of difficulty.
n1337 29 Junior Poster in Training
Ummmm what specifically are you having difficulty with? It is pretty much straightforward OOP...classes and inheritance...
If you haven't learned the subject, thats another issue entirely, in which case I would suggest doing a google search on C++ classes and inheritance, and then posting back here with more specific issues...
n1337 29 Junior Poster in Training
I haven't read your code, but I would guess that you are not tokenizing properly...
I would take a finite state machine (FSM) approach to solving this problem...reading in input character by character, and calling routines based on the input...(somewhat of a C influence I suppose).
With that in mind, you really only have a few tokens to consider, depending on how complex you are making this...
That is, you should account for a number state (if you read a number token), and a symbol state (reading a symbol). So for example, if you read in a character "3", you need to call a routine that peeks at the next character. If it is a number, you need to put the numbers together (i.e. if it is a "5", then you need to make the whole number 35). If it is a symbol, then you move to a different routine that parses symbols (i.e. brackets, operators, etc).
I apologize if that sounds confusing....gotta run!
n1337 29 Junior Poster in Training
The key to these and all problems is to not get overwhelmed...break it down into steps, solve first one step, then continually add more functionality....
So first we need to think about how we can keep track of the customers, both male and female, and in what queue they are waiting...We also need to think about how we can keep track of the time they are in the store...
Let's think about the second question first. One (simple) way of doing this is to just use the function GetTickCount(), which I believe is in the <windows.h> header file...(if you have another/better way of doing this, use it). GetTickCount() simply returns the number of milliseconds that have ellapsed since the system (computer) started...
So you create a variable for each customer that stores "time_entered_store" as just returning GetTickCount() at the time they enter...make sense?
Now you need to think about implementing some sort of data structure to encapsulate the time, and the number of customers...I think it would be natural to create a queue data structure for this question (search google)...one for each queue...I would create something like a queue of customers, where each customer structure keeps track of the time they entered and gender, and then the queue itself points to the customers, and keeps track of the number in each queue....
once you have this sort of functionality, adding the extra logic (to determine which queue a customer enters) should not be too difficult...
… n1337 29 Junior Poster in Training
Also How can I find the order by date?
I'll be honest, I haven't looked at your code at all, partly because its so long and the formatting makes it difficult to read...
But anyway, my first thought when reading the question was to make a struct containing all the required information, i.e. struct order which contains the date of the order, the sku, the description, the price, and a pointer to the next order (like a list). This way, you can add orders in constant time....Then you can just create accessors to return the information that you query...
Another way you could do it is in each class, create side-by-side arrays (or vectors to have the added capability of resizing the array to add a new order). That is, you have a date array, a sku array, etc, all of the same size, and you store corresponding orders into the corresponding elements of each array...That way, you just search for the date in the array, and use the index number of the date to return the order (stored in the same index of the other array)...
In any case, of these two ideas I like the list-structure one better, because it can add new nodes in constant time, and will take O(n) time -- roughly proportional to the length of the list (number of orders) -- to find any specific order, which will actually be the same case as with the arrays (because although you have …
n1337 29 Junior Poster in Training
What have you done so far...? What specifically do you need help with?
Do you have any thoughts on how to solve the problem? If so describe them...If you have any code, post it so we can see where you are at with the problem.
EDIT: lol few seconds behind niek_e
n1337 29 Junior Poster in Training
How do you increment playerposn by the dice value?
playerposn += dice_value;
I assume I’ll have to somehow associate every random number generated to a specific variable, which I’ll then add to player position, right?
Everytime you generate a random number, you should store it in your dice_value variable. Then you just use this value to increment the player position. If you have multiple players, you will need to keep track of who's turn it is, and increment the appropriate player position. That is, if it is player 1's turn, increment playerposn1, if player 2, then increment playerposn2, etc (or you could make an array of playerposns to keep things nice and neat). In any case, get one user working before you make multiple ones...
Also, how do I get it to recognise “press space to continue, any other key to exit”. I mean, what stands for space bar in syntax?
A keypress is an event that you will need to fire. There are likely several threads already on this forumn about this topic. If you can't find any, then search for kewords C++, Win32, and Keycode/Keypress/Keydown/Keyup on google.
However, due to the fact that you are fairly new to programming, I would instead suggest you just read in from the console, and have something like "Type c to continue, e to exit". Then just read in the value, do a simple error check, if it is a c, continue, if it …
n1337 29 Junior Poster in Training
I thought that was not the problem but another one arised!!!....Well according to the question I have I have to enter the number of data sets and the required fields. The loops worked right the way i was taking input!! but the problem was in the final output!!...can you resolve??? or anyone???
What niek_e means is that suppose you wanted 2 data sets (the sample sets). When you loop the first time, you input the values, and Pa = 100, Pb = 50, K = 1, L = 1, etc (as an example). But then you loop again, and instead of retaining these values, you overwrite them with the second data set...hopefully that makes sense. In any case, that will be an issue when you want to solve multiple trials...even if you corrected your current algorithm, the program will only ever solve the last data set that is entered.
Ok I am going to try one more time to explain it without writing code...I can't do up the code for you (for one because I'm at work and two because this is a great learning experience for you...). As for your comment about the course your taking being a beginner course and not one in logic...well...logic/math/problem solving will ALWAYS be a part of programming, they go hand-in-hand, beginner course or not.
The way I thought of this problem was to construct a "tree" like data structure, with each node being the team that is serving:
round 1 …
n1337 29 Junior Poster in Training
There are also tons of tutorials on the subject, for both openGL and DirectX.
I really suggest that you search for them on google, and if you're serious, then possibly even get a book on the subject, because some of the topics in 3D graphics and game programming are considerably advanced (both mathematically and programmatically), so just looking at somebody else's code will really only teach you to copy, without providing a thorough foundation and understanding of how everything works...
n1337 29 Junior Poster in Training
uhh it seems like your just posting every question from an assignment...what are YOUR ideas to begin with?
EDIT: I apologize, I didn't mean for that to sound harsh, I just want to ensure that you are learning as well, because that is what matters most. It is always best for you to explore the concepts first before appealing for help, and then when you do, let us know what your thought process has been...That way we can help you better (in terms of developing problem solving skills), and also ensure that you are understanding and making an honest effort. I think in a previous post you mentioned you didn't know how the forum runs. One of the tenants is that we are not here to do your homework for you, but to help you along. :)
n1337 29 Junior Poster in Training
Errr...well, if you are dealing with positive integers only, you could construct a loop, then on each iteration through the loop, subtract one from each of the numbers, and the first one to reach 0 is the smallest; the last one to reach 0 is the largest...
hahaha it models the recursive definition of a natural number, but don't do this...lol
n1337 29 Junior Poster in Training
Hi, this is my first time posting to this forum so please let me know if I'm doing anything wrong.
I'm fairly new here also, so I can't tell ya...But as a general rule, I think it is best if you try to search for things on your own before posting...
a. Write the internal representation of “17” in ASCII using two binary numbers
I'm not totally sure what you mean by this, but you can get the ASCII character codes by using the following code:
cout << (int)'1' << endl;
cout << (int)'7' << endl;
In fact, you can find out any character code by replacing the 1 or 7 with whatever character you like. Anyway, the above code will give you 49 and 55, respectively. So I suppose you need to write these numbers in binary...As for doing that, there are several algorithms (to do it by hand), which you can mimic using code (if you need to). I'm sure there is also probably some function written in some library in C++ that will auto convert for you, or you could write one yourself (do a search if you desire). Anyway, the following link explains a few "by hand" algorithms for converting decimal to binary:
http://www.wikihow.com/Convert-from-Decimal-to-Binary
b. Write 17 and -17 in two’s complement notation. Use 8 bits for each
Again, quick google search will reveal how two's complement works. Here you go:
http://en.wikipedia.org/wiki/Two's_complement
c. Write 0100101111112 in …
n1337 29 Junior Poster in Training
I need to be able to initialize player_position for at least 2 players, have them roll the dice, move the players to a new location and determine whether there’s a snake or ladder there, then move them to a new location.
int board[101]; int snake; int ladder; snake = board[5],[15],[25],[30],[45],[53],[62],[78],[81],[93],[96]; ladder = board[7],[12],[28],[35],[40],[59],[65],[73],[88]
i'm sure you can see from here that i'm trying to set positions for snakes and ladders on the board so that whatever random number pops up from the dice, locations will already by marked.
Thanks.
What you have done here isn't all that bad. You initialized an integer array with 101 elements, called board. Good. What you could do then is define a "snake" square to be 1, a "ladder" square to be 2, and a regular square to be 0 (or whatever integers you so desire). Clarification:
#define snake 1 //put this at the top of your project, with the includes
board[5] = snake; //body of your program
Then, there are a couple things you could do to keep track of the players. One idea would be to associate the player with his/her respective board element. That is, create a "playerposn" variable. For example, player 1 starts at 0 (i.e. board[0]). So playerposn = 0. If they role a six, you increment playerposn by 6...now player 1 is at position 6 (i.e. board[6]). Then on each role you simply check if they are on a ladder/snake/regular square, and move them accordingly. To do this …
n1337 29 Junior Poster in Training
One thing was confusing that you did took out the required result, How does it relate to the input Pa,Pb,K,L??? Pa is entered in percent and we have to reduce it to simple as Pa/100, and Pb/100; explain me your output while using the input that is Pa=100,Pb=50,K=1,L=3;
I was only doing one particular case... I wanted to give you a chance to try to extend it to the general case...
Let me try explaining like this: suppose we label each round played as a "node" (just for the sake of explanation). Now, at each node, there are 2 possible outcomes: either A wins, or B wins. So, if we think about this problem recursively, we only need to account for these two possible cases. However, the problem has a little more depth: there are 2 "types" of nodes. There is the node where A serves, and the node where B serves. Thus, at any particular node where A serves, there will be a Pa chance that A wins, and a (1-Pa) chance that B wins (note I'm using Pa and Pb as decimals not percents, same thing). Likewise, at any particular node where B serves, there is a Pb chance that B wins, and more importantly, a (1-Pb) chance that B loses (A wins). The same thing happens at each successive node. Since we are looking for the ways that A wins, all you need to do is connect every possible outcome where A wins L rounds (to …
n1337 29 Junior Poster in Training
As I've been reading various threads on this forum, it seems to me that a lot of people are advocates of vector data structures.
Coming from C, I don't tend to use them a lot...I was just wondering if anyone could tell me how vectors are implemented (at the machine/memory level). I haven't done any searches myself, so links are fine as well.
Thanks :)
n1337 29 Junior Poster in Training
Of course you can allocate memory from the heap during runtime so that the memory doesn't need to be allocated at compile-time, except then you would have to explicitly manage the memory...
Anyway, my point was that if you are going to explain the limitations of a fixed size array, you should understand the trade-off, or what you gain in return. The fixed size limitation is also the thing that makes an array so useful. The trade-off of dynamic (as opposed to fixed) length, which you would get from a data structure such as a list, is that you have constant-time, or O(1), access time. That is, you can index into any element of the array in constant time, no matter the size of the array (this has to do with the memory model, and how things are stored in memory, which I won't get into here...).
n1337 29 Junior Poster in Training
OK I did one case for you, hopefully you can derive a more general case from it:
EDIT: they trim whitespace so nvm, words will have to do...I had a diagram for you...
Ok here we go: A has a 0.5 chance of serving first. If A serves, it has a Pa chance of winning. In this case, Pa = 1, so if A ever gets to serve, it will always win. Thus we have A will win 0.5 in this case (because there is a 0.5 chance that A will serve first).
If B serves first, then at each successive round, A has a 0.5 chance of getting to serve (B has a 0.5 chance of winning a round, and therefore of losing a round as well). Thus, there is a 0.5 chance that A will win the first round if B serves first, so then if A wins that round, it will win all of its next rounds, so that gives 0.25 chance of winning. (0.5 that B serves first multiplied by 0.5 that A wins the round).
If B wins the first, then A again has a 0.5 chance of winning the second round, and therefore has a 0.5*0.5*0.5 = 0.125 chance of winning if B wins the first round.
Using the same logic, A has a 0.5*0.5*0.5*0.5 = 0.0625 of winning if B wins the first 2 rounds.
If we add all this mess up, we get 0.5 + 0.25 …
n1337 29 Junior Poster in Training
how very interesting...
I suppose my point was only that, why would you want to detect a mouse click if only using a text-based console...Hence why I would have never considered exploring the subject on a console...
Thanks for that will!
n1337 29 Junior Poster in Training
The best way (I find) of troubleshooting is to just stick a whole bunch of print statements in your code ( printf()...or I guess you could use cout no difference).
If you stick specific print statements before and after each loop, you can tell whether your program made it to that point or not. This way, you can isolate whatever loop is the problem and work from there. Note that, though your code may enter an infinite loop, the problem may lie in previous code...so keep a sharp eye out!
(Note: I always think it best to force you to think about the problem rather than just giving you a straight up answer. Fact is, every1 runs into these problems, no matter how experienced a programmer you are. So its could practice to learn to troubleshoot your own code. That said, I also didn't bother to analyze your code...thought it would take too long. So this way, its a win win situation -- you learn to troubleshoot, and I don't need to figure out what you are doing in your program ;)
But if you still need help, post back and I, or someone else, will take a closer look...)
EDIT: apparently somebody else has already replied, so nvm :P
n1337 29 Junior Poster in Training
Ummm well, left and right click gets into events and event handling...that is, Win32 programming.
I suggest you start by doing some google searches on this topic ;) As an added bonus, if you learn Win32, you can leave the boring old console and start making pretty GUIs...haha
n1337 29 Junior Poster in Training
you mean like this:
//Code goes here
If so, its like using an html tag (if you know what I mean...)
In any case, you type "code" in square brackets [] --> [ c o d e ] (without the spaces).
Then you insert your code.
Then you type "/code" in square brackets [] again --> [ / c o d e ] (without the spaces).
EDIT: so it will look like this:
[code]
//Code goes here
[/code]
except there are no whitespaces when you type code and /code in the square brackets.
n1337 29 Junior Poster in Training
What part do you need help with?
I seem to keep saying this to everyone...but have you attempted the problem yourself yet? If so, where are you stuck? If not, I suggest you first give it a go, write down on paper some flowcharts...do some problem solving ;) Then post back here.
Regardless, I guess I could be a little more help for now...usually I just say google it, but here is a good starting place if you don't understand classes:
n1337 29 Junior Poster in Training
I was afraid it was an IDE issue...I just always thought that Visual C++ was somewhat bloated...In any case, I'll give it a try.
TY very much for your help :)
n1337 29 Junior Poster in Training
Ummm I'm not quite sure if this is what you are looking for but to keep the console open you could just type the code:
sytem("pause");
(i.e. replace cin.getLine(aLine) with that)
EDIT I'll take a look when I get home...busy now
n1337 29 Junior Poster in Training
One last desparate bump before I let this die...
n1337 29 Junior Poster in Training
i am studying programming design in 5 days...
What do you mean? You are trying to learn a language in 5 days? You have 5 days until an exam? You are preparing for something? I don't follow....Saying you are studying programming design could refer to a lot of different things, and saying you are studying it in 5 days (if you mean you are trying to learn it in 5 days) is almost absurd...Please clarify
i do not know anythings about c++....it is too hard for me now...
Is C++ your first programming language? If so, it would be understandably hard. Regardless, I would almost suggest learning a different language if you are just learning programming, because I personally don't feel C++ is the best "starter" language. Then again, you don't need to get to the more advanced parts of the language until you have a firm grasp on the basic syntax and semantics, so don't let me disuade you from learning if you are set on learning it.
In any case, there are TONS of tutorials (both on the Internet -- google -- and likely on this site as well, and in books and such) that range from basic in material to advanced or expert. So there are lots and lots of resources to help you learn. And since you are just learning, I would definitely recommend you start easy and follow some beginner tutorials.
i have to write pseudoce for it....but i do not know …
n1337 29 Junior Poster in Training
What do you need help with?
Have you done any work on it yet on your own? If not I suggest:
1) Think about it a bit on your own. Think about how the program has to flow, what kinds of decisions you will need to make...in general how you will solve the problem. I often find writing things down very helpful during this process -- flowchart or use pseudocode if you have to...
2) Once you have thought about it (or not), post back here with more specific issues. I mean, sure I could go through and solve the problem for you, but wheres the fun/learning in that? Try it on your own first, that way you will have more understanding of the problem and we can go from there.
(Of course if you already have, then just post back with more specific concerns :) )
n1337 29 Junior Poster in Training
Well....first you need to decide on a sorting algorithm. There are TONS of different ways to sort, I saw a post about a bubble sort, which is a very easy-to-write but inefficient sort, you could do some research about insertion sorts, quick sorts, merge sorts...Like I said, there are tons of sorts. You need to weigh the advantages and disadvantages of each to meet your needs (i.e. speed and efficiency in terms of memory versus ease of writing). I don't know if you have discussed order notation in your CS studies yet...if not then maybe its not important, just choose an easy sorting algorithm...
Secondly, you will need a comparison function...I'm not familiar with standard string functions for C++ (I tended to just implement them as I needed in C), but I would imagine there is a strcmp function somewhere...(you can likely use this to compare the authors)...in any case, strcmp is not difficult to implement.
It might be a useful exercise to think about the type of data you will be comparing...in this case its just an authors name, so you probably don't need to worry too much...(I just mentioned this because the strcmp function, depending on how it is implemented, takes time, which is sometimes neglected, and in certain cases, it would be a useful exercise to take this into account when choosing and optimizing the sort..I'm sorry I don't know if I just made any sense...getting tired...)
Then I would suggest that …
n1337 29 Junior Poster in Training
*sigh* not even a single response...perhaps I should try a different forum?
Regardless, I remain hopeful...bump!
n1337 29 Junior Poster in Training
1. A program in C++that alows you to visualize in a table the areas of a circle, and the volume of a sphere for a radio, with a range from 0 to 2, rising by 0.2
visualize in a table how...I'm not totally sure I understand what is expected from this question. Like, do you mean, create a table that has one column containing the radius, moving like 0, 0.2, 0.4, ... , 1.6, 1.8, 2, and then 2 more columns beside it, one for the area of the circle with this radius, and one for the volume of the sphere?
If so, you need to determine how extensively you want to build this table...If you are just writing a console application, then investigate the '\t' escape sequence, and look up the formulas for area of a circle ( pi*(r^2) ) and volume of a sphere ( (4/3) * pi * (r^3) ). Some fancy string formatting will get you a pretty decent table without much trouble...google it.
2.a program in C++, where you give a number (total of money) and it tells you the minimum coins you could have. Coins are 10¢, 20¢, 50¢, 1, 2, 5 y 10 .
Investigate the idea of modulus (it follows closesly with the idea of a | b, or "a divides b", which has to do with integer remainders and such -- it is NOT your regular division, but you probably don't need to get into the math behind it). …
n1337 29 Junior Poster in Training
Well...I'm not totally sure what it is your asking, but I guess I could lead you in a direction that I think is what you are looking for...
Looks to me like you need to create some helper functions (or at least thats what I would do). So for example (I have provided the prototypes for some functions that might be useful):
#include <iostream>
#define SIZE 15
using namespace std;
void enter_grades(double *);
void display_grades(double *);
int main()
{
int choice, answer;
double grades[SIZE], total = 0, average = 0;
cout << "Please select...\n(1) Enter Grades\n(2) " <<
"Display Grades\n(3) Exit\nChoice: ";
cin >> choice;
switch (choice)
{
case 1:
{
enter_grades(grades);
} break;
case 2:
{
display_grades(grades);
} break;
case 3:
{
return 0;
} break;
default:
{
cout << "\n\nYou have entered an invalid choice. " <<
"Program terminated prematurely.";
return 1;
}
}
// compute total and average here, or create a helper function to do it
cout << "\n\nThe total is: " << total << endl;
cout << "The average is: " << average << endl;
system("pause");
return 0;
}
void enter_grades(double *grades)
{
//code here to get the grades
}
void display_grades(double *grades)
{
//code here to display the grades
}
Basically then, based on what the user inputs, you call a corresponding function to accomplish whatever task. This is one way of doing things. Alternatively, instead of using a switch statement, you could just use multiple if statements, but this is a …
n1337 29 Junior Poster in Training
Have you attempted anything on your own?
If not, I suggest first mapping out (conceptually, or on paper) exactly what you have to do. Create a flowchart for program flow if you have to...
For example, a simple diagram of flow could be:
get input from user --> save input in proper format (variable) --> compute averages --> display computations
Next, try to translate your ideas into code or "pseudocode" to start. If you do this, you'll find your problem is actually not very difficult at all.
Finally, once you have a working shell for your program, you can consider adding more complex features. For example, you may want to include some error checking in your code, and make your code fool-proof (so that it wont break in certain conditions). If your really up to it, you may also want to create a GUI-complete "mark program".
In any case, start with the flowcharts and pseudocode (I know this might seem silly for this problem, but its a good habit to get into), and do some problem solving to figure out what it is you have to do. Then try to translate it into some code. Things to think about: how are you going to get user input, how will you store it, how do you calculate averages...just break the problem down, get one part working at a time, and you'll find it a much less daunting task.
(I have to go for lunch …
n1337 29 Junior Poster in Training
You could always try to implement vectors (or alternatively, lists) yourself...using structs and pointers...its actually probably a good exercise, but you may not be allowed to do this either.
n1337 29 Junior Poster in Training
This seems to me like it is just a delimiting problem...
That is, if each link is separated by "<", then u simply need to copy each character that occurs up until this...
Unless I am over-simplifying the problem, all I would do is just a tokenized approach: move through the file character by character. Then you just need to set up a few checks to make sure you are still reading a link (i.e. make sure the character is not a "<", and copy it. You can do this by creating a "PeekCharacter" function, i.e. by storing each character in some sort of buffer and then performing the test...). I would almost be inclined to set up a list structure to store the data...
Hopefully that helps...but I may have misinterpreted your problem..
n1337 29 Junior Poster in Training
I tend to just use arrays of characters as strings....I find them more versatile (and have recently been programming in C, so...)
n1337 29 Junior Poster in Training
Using the incrementor before a variable will first increment the value of the variable and then use this value.
Using the incrementor after a variable will use the current value of the variable, and then increment the variable after.
This is generally just a shortcut or "code-condenser". If the syntax is confusing, play around with it, and put brackets so you remember what is going on :).
For example:
int ctr = 0;
while (ctr++ < 10);
The above loop will test the current value of ctr, then increment it. That is, the first test will be ctr = 0, 0 < 10, then 1 < 10, and so on. EDIT: So if you wanted to print the value of ctr after each iteration, you would print 1, 2, ... , 10.
As opposed to this:
int ctr = 0;
while (++ctr < 10);
We will first increment ctr in this case, and use this incremented value to test if less than 10. That is, the first test will be ctr = 1, 1 < 10, then 2 < 10, etc. EDIT: So if you printed the value of ctr in each iteration, you would print 1, 2, ... , 9.
Hope that helps?
n1337 29 Junior Poster in Training
Hey all,
I have recently become interested in trying to automate various MS Office applications using C++... I was writing some macros in Excel to update some databases that I work with, and decided it would be cool if I could sort of wrap the entire process in a C++ application. (This way I could accomplish a variety of other things from the same application. But regardless, the reasons why I want to do this are both practical and for personal satisfaction)
Anyway, this is more of a personal problem/project that I am working on, so there is no pressure ;)
Heres the thing: I have pretty much no experience working with COM objects...So I am taking this rather slowly. First thing I want to do is actually open an instance of Excel via C++.
But just my luck, the documentation on the subject is rather skimpy or out of date, and msdn is cryptic as always (again, I'm am no expert on the subject, so msdn is really no use to me).
Anyway, to the meat of my post. I have two questions for you:
1) The documentation that I did find had some code examples. Almost all the examples indicated I would need to import the MSO.DLL, among others. So I added the import line (note I also copied the mso.dll to the same directory as my program so that I wouldn't have to specify the entire path, and so that if …