Chapter 0 wrap-up
Before you start: programs, files, and the terminal
Closing thought
Chapter review
One practice set per topic this chapter taught — same fixed, ungraded ladders as the practice panels inside each section.
Practice: Chapter review: source code, compiler, program (4 problems · doesn’t affect your progress)
Which pair is correctly matched?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
That's backwards: .cpp files hold the text you write.
.exe is the executable the compiler makes.
.cpp is text a person reads. It isn't runnable.
Why
The .cpp file is the source. The .exe (or extension-less file on macOS/Linux) is the compiled program.
One file is the text you write; the other is what the compiler produces from it.
hello.cpp is source code; hello.exe is the program
Sort each job by when it happens: while the compiler builds the program, or later, while the finished program runs.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
The compiler reads the source, translates it into machine code and writes the program file. After that, running the program starts at main and does its steps, printing as it goes. The source file plays no part in the run.
Correct answer
Also accepted:
Why
Only one of these two moments ever looks at the .cpp file. Which one?
hello.cpp” → While compiling; “Printing an answer on the screen” → While the program runs; “Turning C++ into machine code” → While compiling; “Starting at main and doing its steps in order” → While the program runs; “Writing the program file, such as hello.exe” → While compiling
What does this print?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Each '\n' ends a line, so Ready and 4 print on separate lines.
Correct answer
Also accepted:
Why
Each '\n' ends a line, and 2 + 2 is worked out before it prints.
Ready ⏎ 4 ⏎
You change a message in hello.cpp and save it, then run the program again without building. What appears?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Saving changes the source file only. The program you run is a separate file, made the last time you built.
Nothing checks the source when the program starts. It runs whatever instructions it was built from.
No restart is involved. Rebuilding is the missing step.
Why
The program is built from the source, and it doesn't change when the source changes. Build again after every edit.
Which file does the computer actually run?
The old message, because the program wasn't rebuilt
Practice: Chapter review: finding your way in the terminal (4 problems · doesn’t affect your progress)
The terminal says you're in C:\Users\Ada. Which command takes you into cpp-course inside it?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
mkdir would try to create cpp-course, not enter it.
ls cpp-course lists that folder's files but leaves you where you are.
pwd takes no folder name. It only prints where you are.
Why
cd cpp-course changes the current directory to the cpp-course folder.
You want to change the current folder, not create, list or print one.
cd cpp-course
You type cd cpp-course, press Enter, and the terminal prints nothing at all. What happened?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
A failed cd does complain, with a message such as no such file or directory. Silence is the good outcome.
cd never shows a folder's contents, empty or not. That's the job of ls.
Pressing Enter finished the command. A fresh prompt line means the terminal is ready for the next one.
Why
cd prints nothing when it succeeds, in PowerShell, zsh and bash alike. pwd confirms it: the path now ends in cpp-course.
Run pwd right after and look at the end of the path it prints.
It worked: you're now inside cpp-course
You're standing in cpp-course/ch01. Order the commands to make a folder ch02 next to ch01 (inside cpp-course), go into it, and check where you are.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
cd .. climbs from ch01 up to cpp-course. mkdir ch02 then makes ch02 beside ch01, cd ch02 enters it, and pwd prints a path ending in cpp-course/ch02.
Correct answer
Also accepted:
Why
mkdir makes the new folder inside whichever folder you're standing in. Where do you need to stand first?
Sort each command: does it reach the same folder no matter where the terminal is standing, or only from the right starting folder?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Paths that start with ~, / or a drive letter such as C: are absolute: they begin at a fixed place, so they work from anywhere. cpp-course and ch01 are relative, so the terminal looks for them inside the current directory.
Correct answer
Also accepted:
Why
Look at how each path begins: with ~, a /, a drive letter, or just a folder name?
cd ~/cpp-course” → Works from any folder; “cd cpp-course” → Only from the right folder; “cd /home/ada/labs” → Works from any folder; “cd ch01” → Only from the right folder; “cd C:\Users\Ada\cpp-course” → Works from any folder
Practice: Chapter review: saving a plain-text .cpp file (4 problems · doesn’t affect your progress)
A line in a .cpp file starts with //. What does the compiler do with the rest of that line?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Printing needs std::cout. A comment never reaches the screen.
The program's file name comes from how you build it, not from a comment.
Programs start at main. A comment isn't a step at all.
Why
// starts a comment: a note for people reading the source. The compiler skips everything from // to the end of the line.
Think of // my first C++ file. Who is that note written for?
Skips it: it's a comment for people
Sort each saved file: could a compiler read it as C++ source right away, or does it need fixing first?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Notepad with All files and nano both save plain text named exactly hello.cpp. The .txt file has the wrong name, the rich-text file stores fonts and layout, and curly quotes are characters C++ doesn't accept.
Correct answer
Also accepted:
Why
Check two things for each card: is the file plain text, and does its real name end in exactly .cpp?
hello.cpp, saved from Notepad with Save as type set to All files” → Ready as C++ source; “hello.cpp.txt, saved from Notepad with the type left at Text documents” → Needs fixing first; “hello.cpp, written in nano and saved with Ctrl+O” → Ready as C++ source; “hello.rtf, saved from TextEdit as rich text, its default” → Needs fixing first; “hello.cpp, but Smart Quotes turned each " into a curly quote” → Needs fixing first
You're saving first.cpp from Notepad's Save as window. What should Save as type be set to?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
With this type, Notepad can add .txt, and the file ends up as first.cpp.txt.
Rich text stores fonts and styles along with the words, which a compiler can't read.
A Word document isn't plain text at all.
Why
With All files selected, Notepad saves the name exactly as typed, first.cpp, as plain text. Left at Text documents, it can quietly add .txt.
You want the name you typed, first.cpp, kept exactly, with nothing added to it.
All files (.)
Finder shows a file called notes.cpp, and you want its full, real name. Which check is certain to show it?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Finder hides extensions by default, so it may be leaving off a .txt.
The first line is the file's contents. The name isn't stored in there.
pwd prints the folder you're in, not the names of the files inside it.
Why
ls lists every file with its full name, extension included. Finder and File Explorer can hide extensions, which is how notes.cpp.txt passes for notes.cpp.
One of these tools never hides any part of a file name.
Run ls in its folder