Question:
5 questions about C++?
Trock
2011-11-16 18:25:40 UTC
Like the title says, I have 5 questions about C++ (I am just learning it).

1. How to make a program update the screen. I mean when a variable that I displayed on the screen, changes, I don't want it to make a new line, I would like the number to change.

2. How to delete text. Like, when I print something on the screen, I would like to know how delete that later on in my program.

3.How many times does a "For" loop operate in a second. ( Just curious)

4. How to add graphics, like adding a picture or a shape and how to change font and colour.

5. How to make character, and obstacles, and add movement , like making a character in a game move, or making a ball bounce, or setting its speed.

I'm just learning, so don't hesitate to tell me if one of the things I want to do is for experts.
Also, just in case it matters, I my compiler is Dev C++.
Four answers:
Techwing
2011-11-16 19:33:07 UTC
1. It depends on your run-time environment. Graphics on the screen are handled differently by each type of computer and operating system. The way you program this depends on whether you are running Windows or Linux or a Mac, etc., and often anything other than putting simple text on the screen can require a lot of complex coding. If you are running the program in a console window on Windows, you can often use ANSI escape codes to control text on the screen.



2. See above.



3. It depends on what's in the loop. An empty loop—one that does nothing but go round and round—will be executed literally billions of times per second by a typical desktop computer.



4. See (1) above. The more complex the graphics, the more complex the programming. Anything that involves graphics tends to be very complicated.



5. See above.



You don't have to be an expert to do graphics, but it takes a lot of learning and experience. If you are programming for Windows, get the (huge) book Programming Windows by Charles Petzold, which will explain all about how to write programs under Windows, including programs that do graphics. You will probably find that it's a lot more complicated than you ever anticipated, but if you really want to do graphics you can learn it by reading the book.



The compiler doesn't matter too much, but do keep in mind that, if you're writing for Windows, Microsoft has a free development environment, Microsoft Virtual C++ 2010 Express, that you can download directly from their site, here:



http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
Blackcompe
2011-11-16 18:54:27 UTC
1 & 2. Whatever you display on the console is their forever. You cannot delete or edit any text, at least not with any of the ANSI C/C++ libraries. All you can do is output text to the screen.



3. Depends on what's in the loop. For an empty infinite loop, there is one statement that's continually executed: the increment (i++).



for(int i = 0; true; i++)



You need some knowledge of assembly language just to make a rough estimate. E.g An infinite loop in MIPS assembly



add $t0, $zero, $zero # i is initialized to 0, $t0 = 0

Loop: // stuff

addi $t0, $t0, 1 # i ++

j Loop # go to Loop if i < 4



If the add instruction takes 4 clock cycles and the jump instruction takes 3 cycles, that's a total of 7 cycles per iteration. If my processor runs MIPS code natively, and runs at 3 GHZ, which is 3 x 10^9 cycles per second, then (3 x 10^9)/7 = a half a billion iterations can be executed. That's an upper limit. Processes don't run for 1 second each. They may get 50 ms to run before being switched out of the processor. If you want a real time estimate, just time it using the languages' libraries.



4. You need to use a Widget toolkit (a.k.a graphics/UI library) for GUI development. See wxWidgets, Windows MFC, GTK+, QT for C/C++, and Swing for Java.



5. Same thing, you need a graphics library.



Graphics development is quite a step up from console development, you'll need a solid base in programming foundations first. At the very least, there's some simple math involved in almost all animations.
anonymous
2016-11-19 11:29:09 UTC
a million) what may be the final Anime you watch this 3 hundred and sixty 5 days? = D. gray guy 2) what may be the final Manga you examine this 3 hundred and sixty 5 days? = Rave grasp 3) what may be the 1st Anime you watch next 3 hundred and sixty 5 days? =D. gray guy 4) what may be the 1st Manga you examine next 3 hundred and sixty 5 days? =Rave grasp XP incredibly lots the comparable 5) what's your suitable 3/5/10 songs of the three hundred and sixty 5 days? T.T uhu..its incredibly lots sow rock and RnB >.>" ima sucker for luv songs.. a million. "we belong at the same time"=mariah carey 2. "never had a dream come authentic"= forgot 3. "Heaven"= DJ Sammy 4. "once you're saying no longer something in any respect"= Ronan Keating (sp?) 5. "Your parent Angel" = forgot.. 6. Butterfly Kiss= idk, frm rave grasp 7. "the worldwide"=Nightmare 8. "born" = Okuda Miwako 9. "Dearest" = Ayumi Hamasaki 10. "each and every heart" BoA guy..i sound like my mom while she's crying over some songs for the frst 5>.<" nicely aside from variety 7..
??????
2011-11-16 18:51:11 UTC
1) you can't that requires a scripted window



2) you can include a library with a clear screen function



3) depends on how much code is inside it, and the speed of your processor



4) you don't again requiring scripted windows



5) Basically too advanced, again using scripted windws


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...