Skip to main content

Fifteen Exercises for Learning a new Programming Language

1. Display series of numbers (1,2,3,4, 5....etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).

2. Fibonacci series, swapping two variables, finding maximum/minimum among a list of numbers.

3. Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.

4. Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, V= velocity, rho = density mu = viscosity
Write a program that will accept all values in appropriate units (Don't worry about unit conversion)
If number is < 2100, display Laminar flow,
If it’s between 2100 and 4000 display 'Transient flow' and
if more than '4000', display 'Turbulent Flow' (If, else, then...)

5. Modify the above program such that it will ask for 'Do you want to calculate again (y/n), if you say 'y', it'll again ask the parameters. If 'n', it'll exit. (Do while loop)

While running the program give value mu = 0. See what happens. Does it give 'DIVIDE BY ZERO' error?
Does it give 'Segmentation fault..core dump?'. How to handle this situation. Is there something built in the language itself? (Exception Handling)

6. Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus

7. Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations)

8. Open a text file and convert it into HTML file. (File operations/Strings)

9. Time and Date : Get system time and convert it in different formats 'DD-MON-YYYY', 'mm-dd-yyyy', 'dd/mm/yy' etc.

10. Create files with date and time stamp appended to the name

11. Input is HTML table, Remove all tags and put data in a comma/tab separated file.

12. Extract uppercase words from a file, extract unique words

13. Implement word wrapping feature (Observe how word wrap works in windows 'notepad')

14. Adding/removing items in the beginning, middle and end of the array.

15. Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc.

Is there something called 'namespace / package / module' supported by your language? (Name mangling) - Read More on this.

Article written by Prashant N Mhatre.

Comments

Popular posts from this blog

Play against Xbox360 gamer on PC in Vista

Microsoft Corp. co-founder Bill Gates on Tuesday announced a cross-platform gaming service that integrates games played on cell phones, Xbox 360 consoles and the upcoming Windows Vista operating system. The "Live Anywhere" service will be available as part of Windows Vista, Microsoft's next-generation PC operating system. The consumer version is scheduled for release early next year. "It means that you have one online community," Gates said in a news conference. "This platform can really unleash developers to do amazing new things." The system would extend the company's existing Xbox Live service for the Xbox 360 console into millions of Internet-enabled PCs and cellular phones. No pricing information on the new service was announced. In recent months, Microsoft has been pushing a number of online services that it hopes will boost revenue as markets for its traditional software become increasingly saturated. The company expects to make money off s...

Web users to 'patrol' US border

A US state is to enlist web users in its fight against illegal immigration by offering live surveillance footage of the Mexican border on the internet. The plan will allow web users worldwide to watch Texas' border with Mexico and phone the authorities if they spot any apparently illegal crossings. Texas Governor Rick Perry said the cameras would focus on "hot-spots and common routes" used to enter the US. US lawmakers have been debating a divisive new illegal immigration bill. The Senate has approved a law that grants millions of illegal immigrants US citizenship and calls for the creation of a guest-worker programme, while beefing up border security. But in order to come into effect, the plan must be reconciled with tougher anti-immigration measures backed by the House of Representatives, that insist all illegal immigration should be criminalised. The issue has polarised politics and US society. Right-wing groups have protested against illegal immigrants, while ...

US says world safer, despite 11,000 attacks in '05

The U.S. war on terrorism has made the world safer, the State Department's counterterrorism chief said on Friday, despite more than 11,000 terrorist attacks worldwide last year that killed 14,600 people. The U.S. State Department said the numbers, listed in its annual Country Reports on Terrorism released on Friday, were based on a broader definition of terrorism and could not be compared to the 3,129 international attacks listed the previous year. But the new 2005 figures, which showed attacks in Iraq jumped and accounted for about a third of the world's total, may fuel criticism of the Bush administration's assertion that it is winning the fight against terrorism. Asked if the world was safer than the previous year, U.S. State Department Counterterrorism Coordinator Henry Crumpton told a news conference, "I think so. But I think that (if) you look at the ups and downs of this battle, it's going to take us a long time to win this. You can't measure this month ...