Simple C++ Program. #include <iostream> using namespace std; int main() { //Note cout << Hello World << endl; return 0;

Similar documents
Software Design & Programming I

Come and join us at WebLyceum

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

for (int i = 1; i <= 3; i++) { do { cout << "Enter a positive integer: "; cin >> n;

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

File Operations. Lecture 16 COP 3014 Spring April 18, 2018

PROGRAMMING EXAMPLE: Checking Account Balance

Files Total: // Files Example 1. #include <iostream> #include <fstream>

Fundamentals of Programming Session 25

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

IS 0020 Program Design and Software Tools

Arrays in C++ Instructor: Andy Abreu

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Week 3: File I/O and Formatting 3.7 Formatting Output

C++ Programming Lecture 10 File Processing

File I/O Christian Schumacher, Info1 D-MAVT 2013

Fundamentals of Programming Session 27

Introduction to C ++

I/O Streams and Standard I/O Devices (cont d.)

Example 3. #include <iostream> using namespace std; int main()

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

LAB 4.1 Relational Operators and the if Statement

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York

Simulations. buffer of fixed capacity using the STL deque. modeling arrival times generating and processing jobs

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

Declaring a 2D Array

Honors Computer Science C++ Mr. Clausen Program 3A, 3B, 3C

Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;

Elements of C in C++ data types if else statement for loops. random numbers rolling a die

Scientific Computing

CS2141 Software Development using C/C++ Stream I/O

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

C++ Input/Output: Streams

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

Lab 8 The Stack (LIFO) Structure

File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)


CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

CS201- Introduction to Programming Current Quizzes

Chapter 15 - C++ As A "Better C"

Lab 7 (50 pts) Due Sunday, May 20)

Objects and streams and files CS427: Elements of Software Engineering

Lab 15 Review of Arrays, Array of Objects and Vector Dr. John Abraham, Professor

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

More File Operations. Lecture 17 COP 3014 Spring april 18, 2018

CS 1704 Homework 2 C++ Pointer Basics Fall 2002

1. (18 pts) Short Answer. Provide brief (1-3 sentence) answers to the following:

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

Dynamic Allocation of Memory

Pre- Defined Func-ons in C++ Review for Midterm #1

Lecture 9. Introduction

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

Pointers II. Class 31

CSCE 206: Structured Programming in C++

PIC 10A. Final Review

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

LAB 7.1 Working with One-Dimensional Arrays

C Legacy Code Topics. Objectives. In this appendix you ll:

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Input and Output. Data Processing Course, I. Hrivnacova, IPN Orsay

Strings and Stream I/O

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

Why Is Repetition Needed?

Preview 8/28/2018. Review for COSC 120 (File Processing: Reading Data From a File)

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

Lectures 19, 20, 21. two valid iterators in [first, last) such that i precedes j, then *j is not less than *i.

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

Recap: Pointers. int* int& *p &i &*&* ** * * * * IFMP 18, M. Schwerhoff

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream

Exercise: Inventing Language

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

The cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;

C/C++ Programming Lecture 7 Name:

Chapter 3 - Notes Input/Output

a data type is Types

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

What we will learn about this week:

Computational Physics

Introduction to C++ (Extensions to C)

CSci 1113 Midterm 2. Name: Student ID:

Streams. Rupesh Nasre.

Object Oriented Programming COP3330 / CGS5409

Standard Library. Lecture 27. Containers. STL Containers. Standard Library

Arrays. Lecture 9 COP 3014 Fall October 16, 2017

Pointers and Strings Prentice Hall, Inc. All rights reserved.

Loops and Files. of do-while loop

C++_ MARKS 40 MIN

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil

Chapter Four: Loops II

Page 1 Name: CUNYfirstID: CS111 Summer Term 1- Final 6/27/18

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Transcription:

Programming Review

Simple C++ Program cout << Hello World << endl;

Variables gpa = 4.0;

Formatting gpa = 4.0;

Conditionals gpa = 4.0; cout << Letter Grade is cout << an A ; cout << not A ;

Control Structures times = 3; gpa = 4.0; cout << Letter Grade is ; cout << an A ; cout << not A ; cout <<! ;

Functions double calculategpa() return 4.0; times = 3; gpa = calculategpa(); cout << Letter Grade is ; cout << an A ; cout << not A ; cout <<! ;

times = 3; gpa = calculategpa(); Function Overloading cout << Letter Grade is ; cout << an A ; cout << not A ; cout <<! ; double calculategpa() return 4.0; double calculategpa(double g1) return g1; double calculategpa(double g1, double g2) return (g1 + g2) / 2.0;

Default Function Parameters times = 3; gpa = calculategpa(); double calculategpa(double g1 = 4.0) return g1; double calculategpa(double g1, double g2) return (g1 + g2) / 2.0; cout << Letter Grade is ; cout << an A ; cout << not A ; cout <<! ;

Pass By Reference gpa = calculategpa(&times); double calculategpa(int& times, double g1 = 4.0) times = 1; return g1; double calculategpa(int times, double g1, double g2) times = 2; return (g1 + g2) / 2; cout << Letter Grade is ; cout << an A ; cout << not A ; cout <<! ;

Random Number Generation #include <cstdlib> #include <ctime> srand(time(0)); gpa = calculategpa(&times); double calculategpa(int& times, double g1 = 4.0) times = rand() % 10; return g1; double calculategpa(int times, double g1, double g2) times = (rand() % 10) + 1; return (g1 + g2) / 2; cout << Letter Grade is ; cout << an A ; cout << not A ; cout <<! ;

#include <cstdlib> #include <ctime> #include <fstream> ofstream output; srand(time(0)); gpa = calculategpa(&times); output.open( gpa.txt ); File I/O double calculategpa(int& times, double g1 = 4.0) times = rand() % 10; return g1; double calculategpa(int times, double g1, double g2) times = (rand() % 10) + 1; return (g1 + g2) / 2; output << fixed << showpoint << setprecision(2); output << GPA: << gpa << \n ; output << Letter Grade is ; output << an A ; output << not A ; output <<! ; output.close();

#include <cstdlib> #include <ctime> #include <fstream> ofstream output; srand(time(0)); gpa = calculategpa(&times); output.open( gpa.txt ); Arrays double calculategpa(int& times, double g1 = 4.0) times = rand() % 10; return g1; double calculategpa(int times, double g1, double g2) times = (rand() % 10) + 1; return (g1 + g2) / 2; output << fixed << showpoint << setprecision(2); output << GPA: << gpa << \n ; output << Letter Grade is ; output << an A ; output << not A ; output <<! ; double calculategpa(double grades[], int number) double ret = 0.0; for (int i = 0; i < number; i++) ret += grades[i]; ret /= number; return ret; output.close();

#include <cstdlib> #include <ctime> #include <fstream> int *times; ofstream output; srand(time(0)); times = new int; gpa = calculategpa(times); output.open( gpa.txt ); Pointers and Memory Allocation double calculategpa(int* times, double g1 = 4.0) *times = rand() % 10; return g1; double calculategpa(int times, double g1, double g2) times = (rand() % 10) + 1; return (g1 + g2) / 2; output << fixed << showpoint << setprecision(2); output << GPA: << gpa << \n ; output << Letter Grade is ; output << an A ; output << not A ; for (int i = 0; i < *times; i++) output <<! ; output.close(); delete times; double calculategpa(double grades[], int number) double ret = 0.0; for (int i = 0; i < number; i++) ret += grades[i]; ret /= number; return ret;

Need More? Professor Myers' COP3014 lecture notes: http://www.cs.fsu.edu/~myers/c+ +/notes/index3014.html