I'm starting to learn C++ but I would like to find some problems to practice my skills on. I don't know that much except for the very basic like looping and if-statements (Didn't learn to make a class yet because I'm preoccupied with studying for midterms as of now).
So does anyone have something I can work on or a website with things of this sort?
Thanks.
Welcome to ScienceForums.Net!
|
After you've registered, come in and introduce yourself, or visit the forum index. If you need any help registering, posting, or if you just have some questions about our site, please feel free to contact us at staff at scienceforums dot net.
|
|
| Guest Message © 2012 DevFuse | |
Page 1 of 1
Any Programming challenges for a C++ beginner?
#1 10 January 2012 - 09:49 PM
"Should we force science down the throats of those that have no taste for it? Is it our duty to drag them kicking and screaming into the twenty-first century ? I am afraid that it is."— George Porter (1920- ), British chemist
"When you are courting a nice girl, an hour seems like a second. When you sit on a red-hot cinder, a second seems like an hour. That's relativity."— Albert Einstein
"Nature is trying very hard to make us succeed, but nature does not depend on us. We are not the only experiment."— R. Buckminster Fuller
Can't we just get along? (To the bickering children in the religion section)
"When you are courting a nice girl, an hour seems like a second. When you sit on a red-hot cinder, a second seems like an hour. That's relativity."— Albert Einstein
"Nature is trying very hard to make us succeed, but nature does not depend on us. We are not the only experiment."— R. Buckminster Fuller
Can't we just get along? (To the bickering children in the religion section)
- Posts: 29 | Joined: 09-September 10
Reply
#2 10 January 2012 - 10:59 PM
Create a class "Polynomial" that represents functions of the type
(hint: constructor)
This program should be appropriate for a ambitious beginner, teach some basics of c++, and keep you occupied for some time (so don't worry if you are not finished with all those points after a day).
(hint: constructor)- Create a method of that class that prints out pairs of x and f(x) over a specified range and with a specified distance between subsequent x. An output of this would look like
x f(x) -1 0.5 -0.8 0.4 -0.6 0.3 -0.4 0.2
(hints: method, std::cout)
- Do the same but write to a text file rather than the screen (hint: std::ofstream)
- Not directly C++ related by arguably even more important for a scientist: Plot these data with a program of your choice to visualize the function. Use the program's built-in function parser to verify that the data you were writing out is correct. (hint: gnuplot)
- Extend the class to handle functions of the type
(hint: std::vector)
- Implement an algebra over these objects, i.e. overload operators such than you can add two of these objects (
) and allows to multiply them with a real ( d * f(x) = d*a0 + d*a1*x + ...) (the term is "operator overloading").
- Implement a method that finds the maximum f(x) over a given range [x0; x1] (no hint: there's several ways and the purpose of this task already is to spark your ambition to try out things for yourself).
This program should be appropriate for a ambitious beginner, teach some basics of c++, and keep you occupied for some time (so don't worry if you are not finished with all those points after a day).
This post has been edited by timo: 10 January 2012 - 11:01 PM
Forum madness is no excuse for forum rudeness (after H.J. Farnsworth)
- Posts: 2,862 | Joined: 02-May 04
Reply
#4 11 January 2012 - 05:30 PM
Learning to program 3D Animations using DirectX or OpenGL are probably the most amusing projects to help you learn C++ IMO. This also teaches you to work with developed libraries, develops understanding of program structure, and also forces you into using most of the features of the language. Although bone animation can be a little tricky in terms of mathematics and a good understanding of the related matrix mathematics is necessary, learning these can be fairly simple as well. There are a lot of online resources that explain how to do these things, where I'm not so sure the depth of information is covered in other topics like extranet banking transactions.
"He is their god! He leads them like a thing made by some other deity than Nature that shapes man better. And they follow him against us brats with no less confidence than boys pursuing summer butterflies, or butchers killing flies." - Cominius; Shakespears Coriolanus
- Posts: 1,519 | Joined: 31-August 08
Reply
#6 19 January 2012 - 08:38 PM
NotanOriginalName, on 19 January 2012 - 02:45 PM, said:
WAP which prints its own source code.Its rather easy but really interesting for a starter.
A Quine, a code that prints its own source code. It's not an easy thing, at least for understanding how it's done.
.. do you know what is the shortest Quine ?
Spoiler
- Posts: 569 | Joined: 21-April 10
Reply
#8 19 January 2012 - 09:51 PM
khaled, on 19 January 2012 - 08:38 PM, said:
A Quine, a code that prints its own source code. It's not an easy thing, at least for understanding how it's done.
.. do you know what is the shortest Quine ?
.. do you know what is the shortest Quine ?
Spoiler
Not always.
~> touch Empty.java ~> javac Empty.java ~> java Empty Error: Could not find or load main class Empty
Some compilers/interpreters will choke (giving you output that is not in your source in the form of error messages), or not produce any program output.
The latter could be argued to be a Quine, but it all gets rather philosophical.
What is the output of a program that does not exist?
I'd say it's undefined, rather than nothing.
Mysticism aside, I should address the OP.
Equilibrium:
My own favourite source of problems of this type is project euler http://projecteuler.net/
They're very math oriented, so may or may not be to your liking.
Other than that, some 3D programming as has been suggested would be the way to go.
I don't believe in free will, but I choose to pretend it exists. If I'm helpful press the green button--->
- Posts: 742 | Joined: 25-January 11
Reply
#9 2 February 2012 - 11:22 PM
Although 3D graphics are extremely interesting (one of my largest interests), you're a beginner and you should start with a more simple and easy to complete project.
Way back when I was first learning C++, I made a console-based restaurant tycoon game. It was a relatively easy project and very fun to play with. Like this:
That's just an example of how you can do it. You can integrate all kinds of strategic elements, upgrades and research trees (like marketing insight, or special restaurant equipment) etc.
Have fun!
Way back when I was first learning C++, I made a console-based restaurant tycoon game. It was a relatively easy project and very fun to play with. Like this:
Quote
Patrick's Food Franchise!
Main Menu
1 - New
2 - Load File
3 - Quit
[user enters 1]
You started a new game.
Day 1.
$40000, 1 restaurant(s).
1 - I'm ready. Begin a new day.
2 - Manage the HQ office.
3 - Manage a restaurant building.
4 - Build a new restaurant building (COST: $125000).
5 - Save game.
6 - Go to main menu.
[user enters 3]
Choose the restaurant building you want to manage:
1 - Capital [LEVEL 1]
2 - Cancel
etc...
Main Menu
1 - New
2 - Load File
3 - Quit
[user enters 1]
You started a new game.
Day 1.
$40000, 1 restaurant(s).
1 - I'm ready. Begin a new day.
2 - Manage the HQ office.
3 - Manage a restaurant building.
4 - Build a new restaurant building (COST: $125000).
5 - Save game.
6 - Go to main menu.
[user enters 3]
Choose the restaurant building you want to manage:
1 - Capital [LEVEL 1]
2 - Cancel
etc...
That's just an example of how you can do it. You can integrate all kinds of strategic elements, upgrades and research trees (like marketing insight, or special restaurant equipment) etc.
Have fun!
This post has been edited by Ben Bowen: 2 February 2012 - 11:25 PM
- Posts: 79 | Joined: 07-December 11
Reply
#11 5 February 2012 - 07:20 PM
lightburst, on 5 February 2012 - 12:08 PM, said:
One teacher told me to try and make your own implementation of some of the functions of an STL. You could do that for some of the generic algorithms I suppose. Of course this is assuming you're new to programming in general.
Emulating STL functionality is a great way to learn to program, I wouldn't say that it presents an appropriate challenge level for a beginner though. I think that one should learn how to use a standard vector<> before learning translation units, memory management, template programming, sorting algorithms, and hashing etc. Just my opinion though, I would approach this as an intermediate programmer.
"He is their god! He leads them like a thing made by some other deity than Nature that shapes man better. And they follow him against us brats with no less confidence than boys pursuing summer butterflies, or butchers killing flies." - Cominius; Shakespears Coriolanus
- Posts: 1,519 | Joined: 31-August 08
Reply
Share this topic:
Page 1 of 1

Help
Sign In »
Register Now!


















