20
Review of C++ Lesson 1

Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops

Embed Size (px)

Citation preview

C++ Clearly with Class

Review of C++Lesson 1

This module is a review the basic concepts of C++.

1ObjectivesReview the following :FlowchartingVariable declarationsOutputInputArithmetic CalculationsConditional StatementsLoops

We will review the following topics: Flowcharting, Variable declarations, Output, Input, Arithmetic Calculations, Conditional Statements, Loops

2ProblemRead in a year and determine if it is a leap year. A leap year is a year that is evenly divisible by 4 and not by 100. Or, a year that is evenly divisible by 400 is also a leap year.

We will use the following problem to review these concepts.Read in a year and determine if it is a leap year. A leap year is a year that is evenly divisible by 4 and not by 100. Or, a year that is evenly divisible by 400 is also a leap year.

3FlowchartPromptRead in yearLeap Year?Is not leap yearIs leap yearEndStartTF

Before you start writing code, you need to have a plan. Think of it this way, before you start building a house, you draw a blue print which is a plan for building a house. A flow chart is a plan for solving a computer problem. The flowchart shows you the steps and order necessary to solve a problem.

In our flowchart, the first thing we do is to prompt the user for the year and then read in the year. After we get the year read in, we can test to see if the year is a leap year. If it is, we print out that it is a leap year, if it is not, we print out that it is not a leap year. 4Program Code//Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not#include "stdafx.h"#include using std::cin;using std::cout; using std::endl;int main(){ int year, rem4, rem100, rem400; cout year; rem4 = year%4; rem100 = year %100; rem400 = year % 400; if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout