473,807 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tutorial 1 - What Is Programming?

Banfa
9,065 Recognized Expert Moderator Expert
I felt that this was a good point to start a tutorial on C/C++ programming because clearly we need to have some idea of what we are trying to achieve before we start out. I recently found this definition on the web which I rather like

"Programmin g is planning how to solve a problem. No matter what method is used -- pencil and paper, slide rule, adding machine, or computer -problem solving requires programming. Of course, how one programs depends on the device one uses in problem solving."

This is taken from the ROYAL PRECISION, Electronic Computer PROGRAMMING MANUAL for the LGP-30. For those of you that have not heard of the LPG-30 you may be forgiven because it was first made in 1956 and has long since gone out of production. But it has the rather auspicious claim of being the type of computer that Edward Lorenz was using when he first noted the chaotic nature of weather systems.

Anyway back to what is programming... "planning how to solve a problem", note we are not actually solving a problem, the computer is going to do that for us. If we could solve the problem ourselves we would have no need to write the program. The premise for a program is that we don't have the time, tenacity or memory capabilities to solve a problem but we do know how to solve it so can instruct a computer to do it for us.

A simple example of this is what is the sum of all integers from 1 - 10,000. If you wanted to you could sit down with a pencil and paper or a calculator and work this out however the time involved plus the likelihood that at some point you would make a mistake makes that an undesirable option. However I can write and run a program to calculate this sum in less than 5 minutes
Expand|Select|Wrap|Line Numbers
  1. #include "stdio.h"
  2.  
  3. #define MAX (10000UL)
  4.  
  5. int main(int argc, char **argp)
  6. {
  7.     unsigned long sum = 0;
  8.     unsigned long number;
  9.  
  10.     for(number=1; number<=MAX; number++)
  11.     {
  12.         sum += number;
  13.     }
  14.  
  15.     printf("The sum of all integers from 1 - %lu is: %lu\n", MAX, sum);
  16.  
  17.     return 0;
  18. }
  19.  
This gives the result 50005000. As it happens I can verify this because I know that the sum of integers from 1 - N can be calculated as

(N+1)*(N/2)

(10000 + 1)*(10000/2) = 10001*5000 = 50005000

So I have solved the problem of how to calculate the sum of all integers from 1 - 10000 and the computer has solve the problem of calculating the sum of all integers from 1 - 10000.

And this is the crux of all computer programs; you can not program a computer to solve a problem unless you know how to solve that problem. There is no point even sitting at your computer with the intention of programming until you have the knowledge, be that a formula from a text book or a design document or a print out from a web page, of how you are going to set about solving the problem.

So programming is the production of a set of instructions that describe how a problem can be solved. There are many languages in which these instructions may be written, for instance on the back of a bottle of shampoo you will often find the instructions describing how to solve the problem of making dirty hair clean:
  1. Wet hair
  2. Rub in shampoo to create a lather
  3. Rinse Hair
  4. Repeat
Note that because this set of instructions is aimed at human beings it makes a couple of assumptions. In step 4 for instance it makes the assumption that normal English is in use and that the instruction will actually be read as “Repeat Once”. It is also likely that an human running these instructions will not repeat step 1 because their hair will already be wet so they will judge it unnecessary to repeat that step.

And that is one of the major differences between humans and computers. Humans have judgement and free will and will not run any instruction they deem not required or nonsensical where as a computer will do exactly what it is told with no judgement on the need or sanity of the instruction. Give the instructions above to your computer and it will never get out of the shower.


Tutorial 2: How to Program
Nov 29 '06
17 79405
fineupall
5 New Member
personally i prefer to write my code like this...

Expand|Select|Wrap|Line Numbers
  1. x=0
  2. (1..10000).each{ |i| x+=i }
  3. puts "The sum of all integers from 1 - 10000 is: #{x}"
  4.  
name that language!
Yes, that's Ruby definitely.
Jun 3 '08 #11
notahat
1 New Member
Yes, that's Ruby definitely.
It's not good Ruby though! (Sorry...can't resist.)

Expand|Select|Wrap|Line Numbers
  1. x = (1..10000).inject(0) {|total, i| total + i }
  2. puts "The sum of all integers from 1 - 10000 is: #{x}"
  3.  
Or, if you want to abstract out the sum:

Expand|Select|Wrap|Line Numbers
  1. module Enumerable
  2.   def sum
  3.     inject(0) {|total, i| total + i }
  4.   end
  5. end
  6.  
  7. puts "The sum of all integers from 1 - 10000 is: #{(1..10000).sum}"
  8.  
Jun 3 '08 #12
jblanch
1 New Member
And this is the crux of all computer programs; you can not program a computer to solve a problem unless you know how to solve that problem.
I disagree with this statement. There are lots of built in functions and libraries that are able to do things that i might never learn how to do. personally i think your logic is flawed from either side of the opposing argument. If you're saying that we're limited to what we know, then why can't i just apply my binary skills to create any imaginable form of data and or programs?

i belive what you're saying is partly true, but i think that you miss an important and powerful topic when you present it like this.
Jun 3 '08 #13
JKKellar
2 New Member
As to the specific statement above
(Regarding the difference between computers and people)
This statement is perfectly wrong:
"Humans have judgment and free will and will not run any instruction they deem not required or nonsensical where as a computer will do exactly what it is told.”

It can be readily and consistently observed that a vast majority of people accept, obey and repeat all kinds of irrelevant and nonsensical instructions-
Both created within themselves and all the more received from the outside world

With the advent of programming modeled after neural networks, I'd say the computer has in the very least, the potential to surpass the majority of human beings as far as comprehension
Once that potential is packaged and fulfilled by going mainstream, the only judgment/free will left to the majority people will be the choice to ignore/override the computer's perfect suggestion and choose the wrong result instead
-A concept well mastered already
Jun 3 '08 #14
stevehadd
1 New Member
One note to add about programming of a computer vs human instructions, is that with computers we have the full machine level instruction set known to us, and access to that level. We don''t have that in humans (yet).

One might define programming as specifying transitions in a state machine, considering all data in memorry and everywhere as one state. i.e. given machine state #38742, what instruction # will take me to desired state. Planning how to solve a problem may involve no programming at all.
Jun 3 '08 #15
JKKellar
2 New Member
One note to add about programming of a computer vs human instructions, is that with computers we have the full machine level instruction set known to us, and access to that level. We don''t have that in humans (yet).
Yuh-huh we do-
Well...I don't know about 'we'

People operate on four drives
-Learn
-Bond
-Defend
-Acquire
Try to think of a fifth drive- There isn't one

-THAT means we have just defined a fixed parameter to what it is to be a human

A fixed parameter is a measurement...a measurement is an amount...an amount can be represented by a number...a number can form an equation...equa tions form the basis of code...code dictates a program...a program determines behavior...

Know how to modify the code and you modify the program- You modify the program and you've modified the behavior

People behave
Jun 3 '08 #16
blovi32
2 New Member
Very nice writeup, good job. In school people often are taught math is just memorizing multiplication tables, but we know it is so much more awesome than that
Jun 5 '08 #17
ChrisCraft
1 New Member
This is great, thanks.

I think this has changed my life forever.
Jan 15 '13 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2431
by: Mark | last post by:
Hello. I am new to programming and Python and was wondering if someone could help get me started. I picked Python to start learning to prgram because of some things I have read about it (easy to learn, object oriented, clear syntax, etc...). Can anyone assist in getting me started with learning to program and Python? Recommended reading material? Online tutorials? Recommended development tools (wxpython, pythonwin, etc...)? I am a...
11
3219
by: Guotao Luan | last post by:
Hello All: I notice that there have been frequent questions being asked about template here so I guess it is okay to post this message here. I just wrote a c++ tempalte tutorial/review, I would like to hear feedbacks from other users. I do not have much experience with template myself so I am sure there are many problems or even mistakes in this material. Comments of all types are welcomed. and I also hope this tutorial/review is helpful...
6
2399
by: John Walton | last post by:
Hello, everyone. I just began school, and they already assigned us science fair. Since I'm in 8th grade, I get to do demonstrations for our projects. I'm probably going to demonstrate Python's networking capabilities by writing a simple instant messenger program. I only have a few problems: 1. I know squat about Python network Programming 2. I know nothing about networks
156
7710
by: jacob navia | last post by:
There is a C tutorial at http://www.cs.virginia.edu/~lcc-win32 It is written to go with the compiler, available at the same URL. I have added quite a bit of material, and I would be glad if people in this group give it a try and tell me if I am saying nonsense somewhere. Beware that I am not very orthodox, hence my tutorial
11
2939
by: Magnus Lycka | last post by:
While the official Python Tutorial has served its purpose well, keeping it up to date is hardly anyones top priority, and there are others who passionately create really good Python tutorials on the web. I think 'A Byte of Python' by Swaroop C H is a good beginners tutorial, and 'Dive Into Python' by Mark Pilgrim is a good tutorial for more experienced programmers.
14
2835
by: Bushido Hacks | last post by:
My name is Bushido Hacks. I am a computer science major from the St. Louis, Missouri area. I wrote a new software installation tutorial for C and C++ programmer who want to create programs as well as programs that use OpenGL. My new tutorial is posted at http://www.bushidohacks.com/tutorials/gcc.php The tutorial is informative for anyone who has a REAL interest in object-oriented programming. It is NOT some phoney balogna sales pitch...
2
8555
by: ppuniversal | last post by:
Hello, Can someone tell a good Tutorial on Network Programming in C++, except Beej's Guide and Vijay Mukhi's tutorials. I want to make a Client Server application in C++ which will involve huge amount of thread programming also, so I wanted a good tutorial which can give me good understanding of all the functions used for Network Programming using Standard C++ (and not using any Network Library other than Winsocks and those available in...
37
8269
by: Zabac | last post by:
I am attempting to learn C on a computer that does not have internet access. Can anyone find a C tutorial that can be completely downloaded? I wish to transfer it from a computer that can get online to my computer. (The one that can not get on the internet.) I don't need an absolute beginner tutorial, as I have used Python before. Thanks! - Ian Shearin
2
19357
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how we set about doing that. Every program starts with a specification, this may be a several hundred page document from your latest client or one small paragraph from your professor and pretty much anything in-between. The specification is very...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10628
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10373
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9195
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5547
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.