Jump to content

Recommended Posts

Posted

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.

Posted (edited)

Create a class "Polynomial" that represents functions of the type [math]f(x) = a_0 + a_1 x^2 + a_2 x^2[/math] (hint: constructor)

  1. 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)
     

  2. Do the same but write to a text file rather than the screen (hint: std::ofstream)
     
  3. 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)
     
  4. Extend the class to handle functions of the type [math]f(x) = a_0 + a_1 x^2 + a_2 x^2 + \dots[/math] (hint: std::vector)
     
  5. Implement an algebra over these objects, i.e. overload operators such than you can add two of these objects ([math] f^{(1)}(x) + f^{(2)}(x) = (a_0^{(1)} + a_0^{(2)}) + (a_1^{(1)} + a_1^{(2)}) x + \dots [/math]) and allows to multiply them with a real ( d * f(x) = d*a0 + d*a1*x + ...) (the term is "operator overloading").
     
  6. 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).

Edited by timo
Posted

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.

Posted

WAP which prints its own source code.Its rather easy but really interesting for a starter.rolleyes.gif

 

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 ?

 

 

an empty source code

 

Posted

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 ?

 

 

an empty source code

 

 

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.

  • 2 weeks later...
Posted (edited)

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:

 

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...

 

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!

Edited by Ben Bowen
Posted

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.

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.