Solved

Exercises for teaching C/C++ wanted

Posted on 1998-09-30
11
385 Views
Last Modified: 2012-06-21
Hi everybody,

I am currently teaching someone C/C++ and I think
the best way to teach it is having him program lots
of exercises under guidance.

Are there any C and/or C++ exercises on the _internet_?

I only need the questions (no solutions) but the exercises
should be of increasing difficulty and all of the key
topics should be covered (basic types, functions, pointers,
operators, use of standard library...).

For example, I am searching for exercises like:

1) "Read two numbers from stdin and write the bigger of the two to stdout"
2) "Open a text file and count all the words in it"
3) "Open a text file and count the number of occurrences of each character"
4) "Print the function values of sin(x) to stdout, given a
starting and an ending value and a step size."
...

Thank you,

Patrick

0
Comment
Question by:ppeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1174067
Most textbooks have these sort of exercises at the end of each chapter.  
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174068
I agree, consider having him purchase a book on the subject.  However, on the internet, try going to:

http://www.bruceeckel.com/

for a free book to download (in RTF format I believe).
0
 
LVL 5

Expert Comment

by:yonat
ID: 1174069
Also you can use the exercises from Stroustrup's book, or from Lippman's C++ Primer. I'm sure you can find these books in any academic library.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:arnond
ID: 1174070
0
 
LVL 1

Author Comment

by:ppeck
ID: 1174071
Hi,

thank you for your answers & comments so far.

I know, most books on C++ offer exercises at the end of each chapter, and
I will suggest my student to buy one of these books. What I wanted to
avoid by asking this question, however, was going to a library (bookshop) and browse
10 books or so to find an exhaustive number of exercises from which I can choose
the ones I consider appropriate for my student. I simply want to use the resources
available on the internet for this.

The 2nd link in arnond's proposed answer comes close to what I am searching for.
Bruce Eckel's 2nd edition of 'Thinking in C++' also contains some exercises.
I don't mind if the exercises are part of a C/C++ course and I have to extract them
from there.

Right now, I want to keep the question unanswered. If no better comments/answers
are coming, arnond will get the points. The points will be given at the beginning of
next week.


Patrick

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174072
You should "re-open" / "reject" the current answer if you want to get more people to look at it.  You see, when a question is in the "locked" section of experts-exchange, it tends to get considerably less traffic.  Then, in a week, ask whomever you think provided the best answer to re-submit it as an answer.
0
 
LVL 3

Expert Comment

by:elfie
ID: 1174073
One of my favorite programs is 'write a program that solves the 8-queen problem'.

It's a program that needs to find out how you can place 8 queens on a chess board, so that no queen is able to catch another.

0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1174074
disclaimer: personal opinion...

avoid schildt (sp?).  despite the informal writing style, I've found his examples generally poor and/or confusing (especially compared to Eckel), and had occasionally found myself avoiding his examples and teaching ones i dreamt up myself.
0
 

Expert Comment

by:jlilley
ID: 1174075
My two cent's worth...  Specific programming excercises are all well-and-good up to a point, but to really *learn* a language, pose a series of real-world problems to be solved.  Ideally, these will require some use of basic data structures and algorithms.  Send your pupil off to solve the problem, and then review his/her solution and offer guidance as to how the problem can be solved more elegantly, using less time/memory/disk, etc.  In C++ there is wide leeway for solving problems, and you can use this approach to steer your pupil towards higher-level thinking (i.e., use STL for data structures, etc).

Some personal favorite problems of mine follow.  These are easily defined, but tend to require fairly strong algorithms and data-structures.  Some of these don't really require OO programming, but will teach the fundamentals of the language.  Good solutions will require good data-encapsulation and several class definitions.

Write a tic-tac-toe game.

Write a program to sort all of the input lines.

Write a spell-checker.  This involves finding a word-list on the Internet (easy), and writing a program that accepts the word-list, builds a searchable data-structure, and compares input text against the word-list.

Solve the transitive-closure problem.  The input consists of pairs of symbols, each pair representing an edge in a graph.  Read the pairs, build a forest of undirected graphs from the pairs, and "color" each graph a unique color (number).  Output a list of all symbols and their color.

Use OO techniques to build a simple "validated input" program.  The forms input reads a "definition" consisting of a series of prompts followed by the type of input expected.  For each prompt/type pair, the program prints the prompt and reads some input.  If the input does not match the type expected, it prints and error and prompts again.  The idea is that there are classes of data to input (name, SSN, telephone, free-form), and you want to write a "FieldValidation" base class, with subclasses that implement specific validations for their own field type.  A good excercise in when-to-use-polymorphism.

Write simple "tokenizer", which scans the input for recognized patterns.  For each recognized pattern, it creates and returns a subclass of Token, where each subclass represents a pattern.  For example: TokenInteger, TokenIdentifier, TokenFloat, TokenString, etc.  Each Token subclass has specific methods for accessing the data in the form it recognized.  For example, TokenInteger has a GetIntegerValue() method, TokenFloat has a GetFloatValue() method, etc.
0
 
LVL 1

Author Comment

by:ppeck
ID: 1174076
jlilley,

thank you for your elaborate comment. I will consider your exercises
as soon as my student reaches a level where he can possibly solve them ;-)

I will ask arnond to post a dummy answer to get the points.


Thanks everybody,

Patrick

0
 
LVL 3

Accepted Solution

by:
arnond earned 50 total points
ID: 1174077
Here's my dummy answer, Patrick. Thanks...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question