{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE100Lab - Lab Letter Name Lab 1 Algorithms the cout...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab Letter: _____ Name: _________________________________ Lab 1 Algorithms, the cout Statement, and Building Your First Program Pre-Lab: Please read the pre-lab and answer the accompanying questions before your lab session. In this lab, you will learn: how to write an algorithm for a program how to use comments in C++ code how to create a "hello world" program Algorithm: Before you begin writing a program, you should "sketch out" the structure and flow of your code. This helps you to avoid nasty surprises ("Oh shoot, I forgot to get user input!"), and it gives your code a more structured appearance. The best way to plan out your code is to break it up into smaller pieces, separating large processes into distinct steps. Then, using comments (explained below), type those steps into your code using language similar to how your code might work. This is called writing an algorithm . Here is an example of an algorithm for a simple "hello world" program: (don't worry about the slashes, they'll be explained later) // declare necessary includes for the program // the main function header // print "hello world" to the screen Here's what the program might look like after adding C++ code: (again, don't worry if you don't understand the code, we'll go over it in a bit) // declare necessary includes for the program #include <iostream> using namespace std; // the main function header int main() { // print "hello world" to the screen cout << "Hello World!" << endl; return 0; } As you can see, the algorithm matches up with the real code needed to complete the program, and it helps explain what each part of the program is doing. This is called commenting your code. Commenting your code helps you remember what the different parts of your program do, and it helps others (like your TA :-) ) understand what your code does (or is trying to do). It is always a good idea to comment your code, and pseudocoding is a great way to do it. CSE 100 Lab 1 1 /5
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Commenting: Comments are parts of your code that C++ ignores. They allow you to insert human-readable notes into your code so that you (and others) can better understand what's going on. In C++, anything that follows two forward slashes ("//", without the quotes) on the same line will be ignored. In this example: cout << "It was nice to meet you," << endl; // you serpent-tongued charlatan !
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern