Sample Code: OUTPUT Daily Highs & Lows

Similar documents
Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

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

Introduction to C++ (Extensions to C)

Fundamentals of Programming CS-110. Lecture 2

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

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

Introduction to Programming EC-105. Lecture 2

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

C++ Input/Output: Streams

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

LAB 7.1 Working with One-Dimensional Arrays

Ch 6. Functions. Example: function calls function

WARM UP LESSONS BARE BASICS

Getting started with C++ (Part 2)

CSC102 INTRO TO PROGRAMMING WITH PYTHON LECTURE 27 CRASH COURSE IN C++ MICHAEL GROSSBERG

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

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

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

CMPS 221 Sample Final

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

Window s Visual Studio Output

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

Expressions, Input, Output and Data Type Conversions

Problem Solving: Storyboards for User Interaction

TEST 1 CS 1410 Intro. To Computer Science Name KEY. October 13, 2010 Fall 2010

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

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

BITG 1233: Introduction to C++

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

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

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Programming. C++ Basics

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

Definition Matching (10 Points)

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

Program Organization and Comments

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

Lecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type-

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

3.1. Chapter 3: The cin Object. Expressions and Interactivity

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity

BITG 1113: Array (Part 1) LECTURE 8

The C++ Language. Arizona State University 1

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

String Variables and Output/Input. Adding Strings and Literals to Your Programming Skills and output/input formatting

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

PIC 10A. Review for Midterm I

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10

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

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Chapter 3 Problem Solving and the Computer

Learning Objectives: General Description: DONE DONE Structure Chart

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Arrays. Week 4. Assylbek Jumagaliyev

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

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

C++ For Science and Engineering Lecture 12

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

BITG 1113: Files and Stream LECTURE 10

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

2.1-First.cpp #include <iostream> // contains information to support input / output using namespace std;

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

C++ basics Getting started with, and Data Types.

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

IDE: Integrated Development Environment

Laboratory 7. Programming Workshop 2 (CSCI 1061U) Faisal Qureshi.

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

Chapter 3: Expressions and Interactivity

2. Functions I: Passing by Value

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

To become familiar with array manipulation, searching, and sorting.

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

Linked List using a Sentinel

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

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

Module 7 b. -Namespaces -Exceptions handling

Do not turn to the next page until the start of the exam.

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013

Streams. Rupesh Nasre.

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

Practice Exercises #8

System Design and Programming II

Inheritance, and Polymorphism.

More Functions. Pass by Value. Example: Exchange two numbers. Storage Classes. Passing Parameters by Reference. Pass by value and by reference

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

LECTURE 02 INTRODUCTION TO C++

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

1. Which of the following best describes the situation after Line 1 has been executed?

Transcription:

Name1: Name2: Class Day / Time: Due Date: Sample Code: OUTPUT Daily Highs & Lows This program will obtain from the user 3 sets of data including a date, the high temperature and a low temperature for that date. Calculate, store, and output the input and the average temperature in a table (see next page for the example output). Create the pseudocode of your algorithm (don t need to type it). Then convert it into c++ code. Run the code above twice to produce the following output. The class heading only needs to be printed 1 time. Additional Requirements: Use appropriate data types and variable names throughout the code. Do not use spaces or tabs for formatting --- use the manipulators discussed in class The point of this lab is to demonstrate the use of output manipulators so be sure to stick to the output format specified below. Make sure it conforms to the style detailed in the lecture notes including line numbers) printed out directly from main.cpp EXPECTED INPUT/OUTPUT 1 ************************************************** 2 * PROGRAMMED BY : Michele Rousseau & Someone Else 3 * CLASS : CS1A 4 * SECTION : MW - 6p-7:30p 5 * LAB #0 : Output - Daily Highs & Lows 6 **********************************************W**** 7 8 Please enter the date (MM/DD/YY): 08/04/65 9 Please enter the low temperature: 37 Double 10 Please enter the high temperature: 80 Space 11 Triple Space 12 Please enter the date (MM/DD/YY): 12/20/26 13 Please enter the low temperature: 45 14 Please enter the high temperature: 73 15 16 17 DATE LOW HIGH AVERAGE 18 -------- --- ---- ------- 19 08/04/65 37 80 58.5 20 12/20/26 43 73 59.0 21 4 spaces between each column 1 Space Include the class heading for all assignments & labs. (use your name and etc) This should be output from your code (see the eclipse lab) v.s.14

CODE - SOLUTION 1 /************************************************************************* 2 * AUTHOR : Michele Rousseau & Someone Else 3 * STUDENT ID : 123456 & 789101 4 * LAB #00 : Output - Daily Highs & Lows 5 * CLASS : CS1A 6 * SECTION : MW: 7:30a 7 * DUE DATE : 12/20/26 8 *************************************************************************/ 9 10 #include <iostream> 11 #include <iomanip> 12 #include <math.h> 13 using namespace std; 14 15 /************************************************************************* 16 * OUTPUT - Daily Highs and Lows 17 * 18 * This program reads in two sets of data including a: 19 * date, 20 * high temperature, and 21 * low temperature 22 * 23 * It calculates the average temperature for each set and will output a 24 * table including the input data and the average temperatures. 25 * 26 * INPUT: 27 * Two sets of data will be input 28 * ************* 29 * *** set 1 *** 30 * ************* 31 * date1 : Date the temperatures occurred 32 * lowtemp1 : Lowest temperature (as a whole number) for date1 33 * hightemp1 : Highest temperature (as a whole number) for date1 34 * 35 * ************* 36 * *** set 2 *** 37 * ************* 38 * date2 : Date the temperatures occurred 39 * lowtemp2 : Lowest temperature (as a whole number) for date2 40 * hightemp2 : Highest temperature (as a whole number) for date2 41 * 42 * OUTPUT: 43 * This program will out put a table including the input described above 44 * along with: 45 * averagetemp1 : The average temperature for date1 46 * averagetemp2 : The average temperature for date2 47 * 48 *************************************************************************/

49 int main() 50 { 51 /********************************************************************* 52 * CONSTANTS 53 * ------------------------------------------------------------------- 54 * USED FOR CLASS HEADING ALL WILL BE OUTPUT 55 * ------------------------------------------------------------------- 56 * PROGRAMMER : Programmer's Name 57 * CLASS : Student's Course 58 * SECTION : Class Days and Times 59 * LAB_NUM : Lab Number (specific to this lab) 60 * LAB_NAME : Title of the Lab 61 * 62 * ------------------------------------------------------------------- 63 * USED FOR FORMATTING 64 * ------------------------------------------------------------------- 65 * PROMPT_COL : the set width for the prompts 66 * DATE_COL : the column for the area of the triangle 67 * LOW_TEMP_COL : the column for the area of the rectangle 68 * HIGH_TEMP_COL : the column for the area of the circle 69 * AVG_TEMP_COL : the column for the area of the circle 70 * 71 *********************************************************************/ 72 const char PROGRAMMER[] = "Michele Rousseau & Someone Else"; 73 const char CLASS[] = "CS1A"; 74 const char SECTION[] = "MW: 7:30a - 5:00p"; 75 const int LAB_NUM = 00; 76 const char LAB_NAME[] = "Output - Daily Highs & Lows"; 77 78 const int PROMPT_COL = 35; 79 const int LOW_TEMP_COL = 7; 80 const int HIGH_TEMP_COL = 8; 81 const int AVG_TEMP_COL = 11; 82 const int DATE_SIZE = 9; 83 84 char date1[date_size]; // IN & OUT - Set 1: Date for temperatures 85 int lowtemp1; // IN & OUT - Set 1: low temperature 86 int hightemp1; // IN & OUT - Set 1: high temperature 87 float averagetemp1; // IN & CALC - Set 1: average temperature 88 89 char date2[date_size]; // IN & OUT - Set 1: Date for temperatures 90 int lowtemp2; // IN & OUT - Set 1: low temperature 91 int hightemp2; // IN & OUT - Set 1: high temperature 92 float averagetemp2; // IN & CALC - Set 1: average temperature 93 94 95 // OUTPUT - Class heading 96 cout << left; 97 cout << "******************************************************\n"; 98 cout << "* PROGRAMMED BY : " << PROGRAMMER << endl; 99 cout << "* " << setw(14)<< "CLASS" << ": " << CLASS << endl; 100 cout << "* " << setw(14)<< "SECTION" << ": " << SECTION << endl; 101 cout << "* LAB #" << setw(9) << LAB_NUM << ": " << LAB_NAME << endl; 102 cout << "******************************************************\n\n"; 103 cout << right;

104 /******************************************************************** 105 * INPUT - read in two sets of data each containing a: 106 * date, 107 * low temperature, and a 108 * high temperature 109 ********************************************************************/ 110 // INPUT - Set1: date, low temp and high temp 111 cout << left; 112 cout << setw(prompt_col) << "Please enter the date (MM/DD/YY): "; 113 cin.getline(date1, DATE_SIZE); 114 115 cout << setw(prompt_col) << "Please enter the low temperature: "; 116 cin >> lowtemp1; 117 118 cout << setw(prompt_col) << "Please enter the high temperature: "; 119 cin >> hightemp1; 120 cin.ignore(1000, '\n'); 121 122 cout << endl; 123 124 // INPUT - Set2: date, low temp and high temp 125 cout << setw(prompt_col) << "Please enter the date (MM/DD/YY): "; 126 cin.getline(date2, DATE_SIZE); 127 128 cout << setw(prompt_col) << "Please enter the low temperature: "; 129 cin >> lowtemp2; 130 131 cout << setw(prompt_col) << "Please enter the high temperature: "; 132 cin >> hightemp2; 133 cin.ignore(1000, '\n'); 134 135 cout << endl << endl; 136 cout << right; 137 138 139 /******************************************************************** 140 * PROCESSING - calculate average temperatures for both sets of data 141 ********************************************************************/ 142 averagetemp1 = (lowtemp1 + hightemp1) / 2.0; 143 averagetemp2 = (lowtemp2 + hightemp2) / 2.0;

144 /******************************************************************** 145 * OUTPUT - a table with the input data and the average temperature in 146 * columns as follows: 147 * 148 * DATE LOW HIGH AVERAGE 149 * -------- --- ---- ------- 150 * 08/04/65 37 80 58.5 151 * 12/20/26 45 73 59.0 152 ********************************************************************/ 153 154 // OUTPUT - Headings for the table 155 cout << left << setw(date_size-1) << "DATE" 156 << right << setw(low_temp_col) << "LOW" 157 << setw(high_temp_col) << "HIGH" 158 << setw(avg_temp_col) << "AVERAGE" 159 << endl; 160 161 cout << left << setw(date_size-1) << "--------" 162 << right << setw(low_temp_col) << "---" 163 << setw(high_temp_col) << "----" 164 << setw(avg_temp_col) << "-------" 165 << endl; 166 167 // OUTPUT - two sets of data (date, low temp, high temp & average temp) 168 cout << setprecision(1) << fixed; 169 cout << left << setw(date_size-1) << date1 170 << right << setw(low_temp_col) << lowtemp1 171 << setw(high_temp_col) << hightemp1 172 << setw(avg_temp_col) << averagetemp1 173 << endl; 174 175 cout << left << setw(date_size-1) << date2 176 << right << setw(low_temp_col) << lowtemp2 177 << setw(high_temp_col) << hightemp2 178 << setw(avg_temp_col) << averagetemp2 179 << endl; 180 181 return 0; 182 }