Five Core Ingredients Every Program Shares | C++ Programming

UPI Study › Courses › C++ Programming › Free lessons › Lesson 1.2 Free with a free account

Five Core Ingredients Every Program Shares

C++ Programming · Chapter 1: Foundations of ProgrammingSection 1.2 · lesson 2 of 84video coming soon

← Why Learn to Code?Next lesson: Logical Thinking and Code Structure →

Earn 3 college credits for C++ ProgrammingRecommended for credit by NCCRS · Computer Science 242 · self-paced · one payment, lifetime access

In this lesson

What every software program shares.

  • Name the five ingredients of any program
  • Spot them in a cash machine and a thermostat
  • Tell storing a value from showing it
  • Tell a decision from a repetition

Transcript

Everything said in the video, section by section (1,386 words). Read along, or search it.

Opening Question

Why Programs Look Like Punctuation

The first time you look at a working program, the honest reaction is: it's a wall of unfamiliar punctuation. That reaction is normal, and it's also misleading. The vocabulary of programming is large, but the set of ideas underneath it is remarkably small.

Big Idea

The Same Five Ingredients Everywhere

Every program you'll ever meet is assembled from the same five ingredients. A payroll system, a video game, the software in a washing machine, a script that renames a thousand photos: the same five. Different languages spell them differently, but the ingredients themselves don't change. So this lesson uses plain English, on purpose. What you learn here stays true when you meet the exact wording later, in any language.

Overview

Five Ingredients in One Line Each

Here are the five, in one line each. Input brings information in from outside the program. It answers: what am I being given? Output sends information back out. It answers: what do I have to show for it? Storage holds a value under a name, so it can be used later. What do I need to remember? Decision chooses between two paths, based on a condition. Which way should I go? And repetition runs the same steps again, without rewriting them. Do I need to do that again?

Ingredient One

Input Is Anything Coming In

Input is anything that reaches the program from outside itself, while it's running. A program with no input can only ever produce one fixed result. It might be a good result, but it'll be the same today, tomorrow, and in ten years. Typing is only one door in. Information also arrives from a file, a temperature sensor, a barcode scanner, a swiped card, a network message, or another program. A useful habit: when you meet an unfamiliar program, ask first, what can get in? That tells you how much its behavior can vary.

Ingredient Two

Output Crosses the Program Boundary

Output is anything the program sends beyond its own boundary. Text on a screen, but also a saved file, a printed page, a sound, a network reply, a light, or a motor starting to turn. And output matters more than beginners expect. A program can carry out a long, completely correct calculation. If it never sends the answer anywhere, nobody, including you, can tell whether it worked.

Ingredient Three

Storage Is a Labeled Locker

Storage means putting a value somewhere, under a name you choose, so a later step can use it. Think of a locker with a label on the front. You pick the label, like balance, attempts, or customer name. A program only ever does three things with a named holder. It puts a value in. It looks at it, which doesn't use the value up. Or it replaces it. That last one carries the weight: the name stays put, while the contents change. That's how a program keeps a running total across a shopping basket, a count of attempts, or a game character's position. Without named storage, each step would finish its work, and immediately forget it. Nothing could build on anything.

Ingredient Four

Decisions Ask Yes or No

A decision is a point where the program asks a question with only two possible answers, and takes one path or the other. That question is called a condition, and it always resolves to yes, or no. Is the balance at least the amount requested? If yes, hand over the cash. If no, explain that the funds are short. Has the customer used three attempts? Is the room colder than the target? Has the end of the file been reached?

Key Detail

Decisions Settle at the Moment Reached

The crucial detail is when the question is asked. A decision is settled at the moment the program reaches it, using the values as they stand at that instant, not when the program was written. That's why one unchanged program behaves differently on different days. The balance is different, or the sensor reading, or the file is longer. The path changes, because the values changed.

Ingredient Five

Repeating Steps Without Rewriting Them

Repetition means running the same steps more than once, without writing them out more than once. Sometimes the number of times is known in advance. Produce 30 payslips. Print 12 monthly totals. Deal 7 cards to each player. Sometimes it isn't. Keep asking until the number is correct. Read lines until the file runs out. Keep checking the temperature for as long as the device is on.

Common Pitfall

Something Inside Must Change the Answer

Both share a requirement that's easy to overlook. Something inside the repeated steps must be able to change the answer to: again? A count has to climb toward its limit. A new line has to be read. A fresh answer has to be collected. If nothing inside can ever change that answer, the program keeps going round forever. And it does so cheerfully, without any complaint to tell you something's wrong.

Worked Example

Cash Machine: Card and PIN

Nothing about a cash machine is mysterious once the five ingredients are on the table. Here's the whole transaction. The card is read, which is input, and the account number is held for the transaction, which is storage. The screen asks for the personal number, which is output, and the customer types four digits, which is input. The digits are checked against the record, a decision. If they're wrong, the machine asks again, up to three attempts: a repetition.

Worked Example

Cash Machine: Attempts and Withdrawal

And the count of attempts is kept and updated: storage. The customer chooses an amount. The machine checks whether the balance covers it, saves the new balance, and dispenses cash with a receipt. Notice two things. All five ingredients appear, most of them more than once. And they're not in a tidy order: the repetition at step six wraps around several other steps.

Quick Check

Which Ingredient Switches the Heater

A cash machine has a keyboard and a screen, which makes input and output easy to spot. A thermostat on a wall has neither. Quick check: when it switches the heater on, which ingredient is that? Pause, and decide. It's output: a signal sent beyond the program's boundary. No words, and no screen, but still output.

Second Example

All Five Inside a Thermostat

In fact, all five ingredients are there. Input is the temperature the sensor measures right now. Storage is the target temperature the household set. The decision asks whether the measured temperature is below the target. Output is the signal that switches the heater. And repetition is the cycle itself. Measure, compare, act, wait, and then do it all again, indefinitely. A banking machine and a heating control share no hardware, no purpose and no vocabulary. Yet describing what each one does needs exactly the same five words.

Common Mistakes

Three Easily Confused Ideas

Three things are easy to mix up. First, input isn't only someone typing. If it were, a thermostat, a barcode scanner, and a program reading a spreadsheet would have no input. Input is defined by direction: information moving inward. Second, storing a value isn't the same as showing it. Putting a result in a named holder changes nothing anyone outside can observe. Showing it is a separate act: output. Programs that seem to do nothing are very often quietly storing results, and never sending them anywhere. Third, a decision and a repetition both ask a question, so they look alike on the page. The difference is how many times the condition is asked.

Comparison

Decision Versus Repetition Side by Side

Here's that difference side by side. A decision asks its condition once, takes the path the answer implies, and never returns. A repetition asks the same question on every pass, until the answer finally changes. A decision reads like: if this is true, do that. A repetition reads like: while this stays true, keep doing that. And they fail differently. A decision can take the wrong path. A repetition's answer may never change, so it never stops.

Vocabulary

Condition and Path Defined

Two more words to carry forward. A condition is a question about the current values that resolves to yes, or no. And a path is the particular route through the steps that one run actually takes.

Key Takeaways

Five Ingredients Summarized

To summarize. Input brings information in, and output sends it out. Both are defined by direction, not by keyboards or screens. Storage keeps a value under a name. It can be read freely, and replaced, while the name stays the same. A decision asks its condition once. A repetition asks it every pass, and something inside must be able to change the answer. And every program, with a screen or without, is these five ingredients combined.

Think About It

Vending Machine Coin Tracking

Something to think about. A vending machine keeps track of the money inserted, as coins arrive one at a time. Which two ingredients does it need for that, and why can neither one be dropped?

About C++ Programming at UPI Study

C++ Programming (Computer Science 242) is a self-paced online course of 84 video lessons in 11 chapters, from your first program to decisions, loops, arrays, functions, classes, files, pointers and inheritance. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Why take it here

Why students take C++ Programming with UPI Study

Your first real programming languageC++ teaches how programs really work: variables, control flow, functions, memory and objects. It is the base for data structures, algorithms, systems and game programming, and for most computer-science degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

C++ Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Five Core Ingredients Every Program Shares

What are the five ingredients every program shares?
The five ingredients are input, output, storage, decision, and repetition. Input brings information in from outside the program, output sends information out, and storage holds a value under a name for later use. A decision chooses between two paths based on a condition, and repetition runs the same steps again without rewriting them.
How do you find all five program ingredients in a cash machine and a thermostat?
Match each step to the ingredient it performs. In a cash machine, reading the card and typing the PIN are input, the prompt and cash dispensed are output, and the stored attempt count is storage. Checking the PIN is a decision, and retrying up to three times is repetition. A thermostat uses a sensor reading as input, the target temperature as storage, and a below-target check as a decision. Switching the heater is output, and the measure-compare-act cycle is repetition.
What is the difference between storing a value and showing it?
Storing puts a value under a name inside the program, while showing it sends the value out as output. Storage changes nothing anyone outside can observe. A program can finish a correct calculation and keep the result in a named holder, but unless it sends the result out through a screen, file, or signal, nobody can tell it worked.
What is the difference between a decision and a repetition in programming?
A decision asks its condition once and takes one path, while a repetition asks the same condition on every pass until the answer changes. A decision reads like "if this is true, do that." A repetition reads like "while this stays true, keep doing that." A repetition can run forever if nothing inside its steps can ever change the answer.

About the C++ Programming course

How many college credits is C++ Programming?
C++ Programming (Computer Science 242) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does C++ Programming cost and what is included?
$250, paid once, with lifetime access: all 84 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does C++ Programming take?
It is self-paced with no deadlines. The 84 lessons total about 0 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in C++ Programming.

84 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

C++ Programming
3 credits · NCCRS
Enroll →