ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Does anyone care to offer a suggestion on a project for a beginning programmer. I did a project for science fair that took the input temperature from another program, and converted the output to kelvin. I since returned the sensor, or I would ahve kept working on that. That program was written in C++, and that's the language I would like to continue in. Any suggestions?
how about a program that generates good ideas for beginners?
*apologies. late night cynisism*
ok, how about (and I really apreciated this as a learning exercise)
a program that take a given number of things, shuffles them, and returns the result? have you seen those nine letter newspaper problems?
anyway, its late, I'm going to bed now because I can no longer type...
umm... a program to find prime numbers? calculate pi?
These helped me get better at C++ and were the first 'real' pieces of code that really made me think on my own. I had basically read most chapters from an intro C++ book (C++ Primer Plus) and done most excercises. The best 'project' you can do is to read and write alot of code, and work your way through a good textbook over the course of a month to sharpen your general language skills. It might be dry at times, but its worth it, and the programs you write will be much less trivial when your finished.
If you have a good understanding of classes but havent written anything 'real' yet, besides maybe the Time, Shapes or Employee classes that many beginners learn, these are a good place to start.
* Write a string class, from which you can create strings. Overload some common operators, like +, +=, =, == and ensure correct memory management is implemented.
* Get a deeper understanding of C++ classes and Object Oriented Programming from reading a bit. Read a fair amount about pointers and write your own Linked List class. Some common methods you might want to implement would be front/rear insertions and deletions, length checking, and after those are done, implement insertion/deletion anywhere in the list. Research effective algorithms for searching and sorting lists, and try and implement a few. You should have a good enough understanding to use the STL <list> class, compare it to your class, and use the <list> class in some real-world programs.
* Write an array class, similiar to the string class. You might want to do a few things with it - overload assignment operator, perform bounds checking, overload  operator, etc...
* If Lists are easy, try writing an abstract Tree class, and inherit a binary tree class from this.
If these are a little much, read about the following topics and write lots of code using them in C++: pointers, functions, arrays, classes, advanced classes (inheritance, polymorphism), templates and data structures.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
First let me say, good choice to be learning with c++.
Now don't misunderstand, I'm not knocking any other languages, but
c++ is good to learn with because it teaches you many fundamentals
that a lot of other languages (java, 3 p's, c#) just don't.
This is a short program I did in CS 1. Write a program to take a total ($3.68),
and a tendered amount ($5.00), and output the change in english.
So something like this:
Total: $3.68, Tendered: $5.00
Change: 1 dollar, 1 quarter, 1 nickel, and 2 pennies
See if you can extend it to handle all the denominations from penny up to benjamin,
or whatever currency they use wherever you're from. Notice to get the commas
and the 'and' in the right place, you'll have to remember your position. Arrays
can help you do this easily, if you can see how to do it.
Yes, classes are great to make you a good c++ designer. Make a set
class (as in a mathematical set). Have functions and corresponding operators
for union, intersection, complement. You'll find that set classes are useful
in many of the algorithms you use in computer science.
You know how when you play final fantasy (>=8) and you can tell the airship to
auto navigate to a place on the map? Write a program to figure out that.
In other words, assuming the planet is a perfect sphere, and given the
current position, the destination, and the direction the ship is currently facing,
make the program output the degrees the ship should rotate and then the
distance it should travel to get to the destination. The units you use for each
part really don't matter as long as you're consistent.
Hint: shortest distance between 2 points is a straight line, right? So find the
line between them (this will be straight thru the planet). Then follow that line
over the planet's surface. CAREFUL: If you're at the North Pole and trying to
get to the South Pole, you'll have to choose arbitrarily.
Euclidean algorithm: this finds the gcd of 2 integers, google it.
Extended Euclidean algorithm (google that also):
does the same thing but also finds two other integers as well.
If you read some of those links, understand them, and write
a program to calculate them, then you'll understand part of the basis for RSA.
If you don't know, RSA is what make internet security such as credit
card transactions and secure logins work.
EDIT: added another item
Last edited by shakezilla; 06-26-2005 at 12:06 AM.
actually, I've never played final fantasy n. Thanks for all the ideas. Most of those, I don't even have an inkling where to start. Other thoughts? I like the ideas for a high level math program(e.g. prime numbers, pi, Euclidean Algorithm) Thanks again
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Warning: do Euclidean and primes (Sieve of Eratosthenes) before you try
to do pi and the airship problem.
Do you at least know the process of Euclidean algorithm?
Never played ff? Ok, imagine you were going to fly a plane (in a straight line,
non-stop) from Maine to say, St. Petersburg, which is roughly in central Russia,
I believe. Faster to go across the Atlantic, or Pacific?
Well, in this case, probably the Atlantic, but how would you be sure? Probably
the Gobi desert (in Central Asia) is an even better example, although not very
Use the <cstdlib> file and use the rand() function to generate random numbers. Create a huge array (or file, or vector, or list if you want), say about 10,000 elements long, and write a loop to fill it with random numbers.
Research some sorting algorithms (start with the bubble sort, its probably easiest) and sort your list into order. Try and visualize on paper and in your head what's happening in memory.
Say you have an array that looks like this:
59 | 603 | 31 | 792 | 116 | 8
This example array is 6 elements long. Using a bubble sort, we work our way from left to right, comparing the current element, with current element + 1, and swap the elements if right side is less than left. I wont write the whole loop(s) for you, but I'll give you an idea of the first 3 passes through the array. The idea is the smallest numbers "bubble" their way to the top of the array, this algorithm is quite slow compared to other search algorithms, but its a fun one to work out.
Now you see we're almost in order, but we still need 4 more passes to "bubble" 8 to the top of the array. Try it on paper, you'll see what I mean. Each successive pass from now forward will move 8 "up" one more element.
If you understand this well, ask yourself - after the "bottom" elements have been put into order, do we need to do the comparison every time? Can you think of a better way to slightly optimize this algorithm? Figure out the core part first, then come back and try the little optimization trick.
I see. I get the basic premise behind the eulicdean algorithm, I also understood the basic premise on the airship thing. How much programming experiance should I have for each of these projects. Like I said, I've done one project. My project basically took the input from a file(where the temperature was recorded in degrees fahrenheit by another program. I adapted that program so it ran once, and I could do a system call inside my loop), and converted the temperature in kelvin, and printed it to the screen. Other thoughts?
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Go ahead and try to do Euclidean. Write a program to take in 2
values and output their gcd (and LCM for extra), and maybe even
the other 2 values you end up with by doing the extended algorithm.
Go on to arrays if you haven't yet, then classes.
Like lowpro2k3 said, do some searching and sort programs. Here
are the things you'll want to google for:
Keep designing until you feel comfortable with arrays and functions.
Recursion is something you may want to look into, you can try doing
the classic factorial and fibonacci examples with recursion (careful,
start out with small numbers). Start with the factorial, and move on
to the fibonacci, it shows you why recursion isn't always the best way.
Another good thing to try with recursion are maze problems. That can
introduce you to depth first and breadth first searches.
Now do the airship problem.
This one is a lot more advanced, so save it til you're very comfortable.
It is an excellent exercise which will teach very much about arrays,
dynamic memory, classes, operator overloading, and inheritance:
Write classes to implement vectors and matrices (matrix) in c++. Give
them the 4 basic ops (+ - * /) for both scalars and other objects of
their own class type. If that's too easy for you, add functions to get and
set the vectors' values as polar or spherical coordinates, or to do
Guassian Elimination on a matrix.
Like I said, wait a while on that. The reason I mention it to you even
though you're just starting is because it teaches you so many things.
Maybe after all that, you're ready to move on to linked data structures.
These would be things like trees, graphs, stuff like that.
Don't get discouraged, if (when) you get stuck, just slow down, and remember:
Understanding the algorithm is more important than knowing any one
particular language (maybe not when it comes to the job market, but....).
btw, if you're confused about any of the math terms I mentioned here is
a great place to look it up: http://mathworld.wolfram.com/
Their pages are a little on the technical side, but very informative.
Why don't you write a program wich calculates the ö (fi)number in some object (eg.black hole). You could also write an app which calculates in % how slower would be time in an moving reference system(the Einstein-Lorentz equation). I'm currently writing an physics app,both in C and C++ to compare their speed.It gets as input (in kilotons)the power of a nuclear fission reaction,get's an amount of water(in kg) and calculates how much would this amount of water be heated (in Celsius and Kelvin) from this reaction.
although interesting, mathematics problems aren't usually very informative after fib, et. al.
Probably some great things to do would be to design and implement a stream tokenizer. Maybe a pattern matching program. How about a base HTTP server (won't read/write files, just always returns a 404)? They're not that difficult, and are great learning tools.