Introduction To Computer Programming C++ Mr. Clausen Program C11A, C11B

Similar documents
Honors Computer Science C++ Mr. Clausen Program 4A, 4B, 4C, 4D, 4G

Honors Computer Science C++ Mr. Clausen Program 4A, 4B, 4C (4D, 4G)

Honors Computer Science C++ Mr. Clausen Program 6A, 6B, 6C, & 6G

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

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

AP Computer Science Java Mr. Clausen Program 6A, 6B

Honors Computer Science Python Mr. Clausen Program 7A, 7B

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

Arrays in C++ Instructor: Andy Abreu

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

Programming. C++ Basics

The x coordinate tells you how far left or right from center the point is. The y coordinate tells you how far up or down from center the point is.

Arrays in Functions!

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Outline. First Quiz Results. Exercise Five Goals. Question Three. Questions One and Two. Exercise five if statements February 28, 2006

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

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

Program Organization and Comments

LAB: INTRODUCTION TO FUNCTIONS IN C++

Summer Packet 7 th into 8 th grade. Name. Integer Operations = 2. (-7)(6)(-4) = = = = 6.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

Student Outcomes. Classwork. Opening Exercises 1 2 (5 minutes)

Computer Science & Engineering 150A Problem Solving Using Computers

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

or 5.00 or 5.000, and so on You can expand the decimal places of a number that already has digits to the right of the decimal point.

Developed By Strawberry

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

Question 2. [5 points] Given the following symbolic constant definition

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

From Pseudcode Algorithms directly to C++ programs

Chapter 5 C Functions

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

The births of the generations are as follow. First generation, 1945 machine language Second generation, mid 1950s assembly language.

Function Call Example

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions.

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

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

C++ Programming Lecture 11 Functions Part I

Companion C++ Examples

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

3.2 Predefined Functions Libraries. 3.1 Top Down Design. 3.2 Predefined Functions Libraries. 3.2 Function call. Display 3.

6.1 Evaluate Roots and Rational Exponents

Procedural Abstraction and Functions That Return a Value. Savitch, Chapter 4

C++ Programming: From Problem Analysis to Program Design, Third Edition

Understanding main() function Input/Output Streams

LAB: STRUCTURES, ARRAYS,

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

6.096 Introduction to C++ January (IAP) 2009

Creating a C++ Program

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

Getting started with C++ (Part 2)

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

Effect of Scaling on Perimeter, Area, and Volume

4. Java Project Design, Input Methods

CHAPTER 4 FUNCTIONS. 4.1 Introduction

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Outline. Functions. Functions. Predefined Functions. Example. Example. Predefined functions User-defined functions Actual parameters Formal parameters

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

Probably the best way to start learning a programming language is with a program. So here is our first program:

Python Programming Exercises 1

LECTURE NOTES ON PROGRAMMING FUNDAMENTAL USING C++ LANGUAGE

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

CISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software.

Computing and Statistical Data Analysis Lecture 3

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

Function with default arguments

Independent Representation

Introduction to Programming EC-105. Lecture 2

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

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

BUILD YOUR VOCABULARY

Other Loop Options EXAMPLE

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

2.Simplification & Approximation

A First Program - Greeting.cpp

Expressions and Casting

Expressions, Input, Output and Data Type Conversions

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

VBScript: Math Functions

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

PIC 10A. Lecture 3: More About Variables, Arithmetic, Casting, Assignment

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

Chapter 1: Symmetry and Surface Area

- HALF YEARLY EXAM ANSWER KEY DEC-2016 COMPUTER SCIENCE ENGLISH MEDIUM

Chapter 7 Functions. As an example, let us write some code to make a virtual cup of coffee.

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

Name Date. FINAL EXAM STUDY GUIDE Pre-Algebra Course 3

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

Lesson 3: Arithmetic & Casting. Pic 10A Ricardo Salazar

Date Lesson Text TOPIC Homework. SA of Prisms & Pyramids Pg. 441 # 1, 3, 5a, 7b, 11bc, 16. Surface Area of Cylinders WS 6.6

Ch. 12: Operator Overloading

Transcription:

Introduction To Computer Programming C++ Mr. Clausen Program C11A, C11B Program 11A: Cone Heads with Functions 30 points Write a program that calculates the volume of a right circular cone using functions. Do Not Use Any Global Variables in this program! You will have 2 global CONSTANTS, but will use all local variables. Save the program as LastNameFirstNameP11A.cpp in your S: directory. To see a model for this program, look at the source codes for the programs pizza.cpp in the network directory titled: IntroCompProgFiles. Look in the folder, Our Textbook Resources, Data Files Students, Unit 3 C++, and the Lesson 11 folder. As you type all your programs this year, be sure not to type past the 80-column line in Borland C++ 5.02 for Windows. If you have any statements longer than 80 columns, press the return key to wrap the statement around to the next line. 1) Type comments at the beginning of the program to display your name and other information just like those used for program 1A. Make sure to change the program name and program description in these comments, so that the program number, name, and description say what is listed above. 2) Include <iostream.h> so we can use the cout and cin commands. Also include <conio.h> so you can use getch() to leave your output displayed on the screen until the user presses any key to continue, and include <iomanip.h> so we can use the setprecision command. Also include <math.h> so we can use the pow function to raise any base to any power. 4) Declare a constant of type double for PI. Also declare a constant named ONE_THIRD to represent 1.0/3.0, being careful not to use integer division. For example: const double PI = 3.14159; const double ONE_THIRD = 1.0/3.0; 5) Don t forget to include comments for your functions, right before each of your function declarations. Remember that these are the five lines of comments for each function as listed below: //Function: Type the function name here //Type a brief description of what the function does here // //Input: list the variables that are passed into the function here //Output: list the variables that are returned from the function here 6) Declare the function void Display_My_Info( ); in the function declaration section of the program. This should be a void function that doesn t take any parameters and doesn t return any values. In addition, declare functions for: void Get_Data(double & radius, double & height); double Volume(double radius, double height); and void Display_Output(double radius, double height, double volume); The

Get_Data() function should be a void function using reference parameters of type double for radius and height. Volume() should be a value returning function of type double that has value parameters for radius and height and returns the volume of the cone. Display_Output() should be a void function using value parameters to echo the radius and height, and display the volume. Do not use reference parameters ( & ) except where indicated above. 7) Use a comment line with equal signs to separate all of the above from the int main function. For example: 8) Inside the int main() function, declare variables of type double for radius, height, and volume. Initialize each of these variables to 0.0. Call the function: Display_My_Info ( ). This function call should be right after the variable declarations. After this, call the Get_Data() function. Next, call the function Volume in an assignment statement, for example: volume = Volume(radius, height). Finally, call the function Display_Output(). Don t forget to send the actual parameters (arguments) to the functions when you call them. Don t forget that value-returning functions are called in assignment statements, while void functions can be called just by writing the function name including any of the actual parameters (arguments). Also remember that actual parameters (arguments) don t include the data type. Then tell the user to press any key to continue, have your getch() command, and your return 0 command. 9) After the int main() function, have a comment line of subtraction signs to separate the above from your function implementation lines below. For example: //----------------------------------------------------------------------------------------------- 8) Implement all of the functions, separating each one from the others using comment lines of subtraction signs. In the Get_Data function you will need to ask the user to enter the radius and height of the cone. In the Volume function, you will need to calculate the volume of the cone using the following formula: volume = ONE_THIRD * PI * pow(radius, 2) * height; Remember that you need to declare a local variable named volume in the beginning of this function, and don t forget to return this value using a return statement as the last line of this function. In the Display_Output function, echo back the values of the radius, and height, and give the volume of the right circular cone. All of these should be displayed to one decimal place using the setprecision command at the beginning of this function after the variable declaration. 9) After the last function implementation of this program, end your program with two comment lines of equal signs. This signifies the end of your source code. For Example: When you are finished with your program, have tested it thoroughly to make sure that your program is correct, and are sure that you don t need to make any changes, then save your program in the W network mapping, and the Program 11A folder.

Program 11B: Distance Between Two Points 40 points Write a program that calculates the distance between any two points on a graph. The formula is as follows and is a variation of the Pythagorean Theorem. ( ) + ( ) 2 2 1 2 1 2 distance = x x y y Save the program as LastNameFirstNameP11B.cpp in your S: directory. To see a model for this program, look at the source codes for the programs pizza.cpp in the network directory titled: IntroCompProgFiles. Look in the folder, Our Textbook Resources, Data Files Students, Unit 3 C++, and the Lesson 11 folder. As you type all your programs this year, be sure not to type past the 80-column line in Borland C++ 5.02 for Windows. If you have any statements longer than 80 columns, press the return key to wrap the statement around to the next line. 1) Type comments at the beginning of the program to display your name and other information just like those used for program 1A. Make sure to change the program name and program description in these comments, so that the program number, name, and description say what is listed above. 2) Include <iostream.h> so we can use the cout and cin commands. Also include <conio.h> so you can use getch() to leave your output displayed on the screen until the user presses any key to continue, and include <iomanip.h> so we can use the setprecision command. Also include <math.h> so we can use the pow function to raise any base to any power and use the square root function. 3) There are no constants to declare. Do Not Use Any Global Variables in this program! 4) Don t forget to include comments for your functions, right before each of your function declarations. Remember that these are the five lines of comments for each function as outlined below:

//Function: Type the function name here //Type a brief description of what the function does here // //Input: list the variables that are passed into the function here //Output: list the variables that are returned from the function here 5) Declare the function void Display_My_Info( ); in the function declaration section of the program. This should be a void function that doesn t take any parameters and doesn t return any values. In addition, declare functions for: void Get_Data(double & x1, double & y1, double & x2, double & y2); double Distance(double x1, double y1, double x2, double y2); and void Display_Output(double x1, double y1, double x2, double y2, double distance); Do not use reference parameters ( & ) except where indicated above. 6) Use a comment line with equal signs to separate all of the above from the int main function. For example: ================ 7) Inside the int main() function, declare variables of type double for x1, y1, x2, y2 and distance. Initialize each of these variables to 0.0. Call the function: Display_My_Info ( ). This function call should be right after the variable declarations. After this, call the Get_Data() function. Next, call the function Distance in an assignment statement, for example: distance = Distance(x1, y1, x2, y2). Finally, call the function Display_Output(). Don t forget to send the actual parameters (arguments) to the functions when you call them. Don t forget that value-returning functions are called in assignment statements, while void functions can be called just by writing the function name including any of the actual parameters. Also remember that actual parameters (arguments) don t include the data type. Also, don t forget that void functions are called just by writing the function name including any of the actual parameters. Then tell the user to press any key to continue, have your getch() command, and your return 0 command. 8) After the int main() function, have a comment line of subtraction signs to separate the above from your function implementation lines below. For example: //----------------------------------------------------------------------------------------------- 9) Implement all of the functions, separating each one from the others using comment lines of subtraction signs. In the Get_Data function you will need to ask the user to enter two ordered pairs: (x1, y1) and (x2, y2). In the Distance function, you will need to calculate the distance between the two points using the following formula: distance = sqrt(pow((x1 x2), 2) + pow((y1 y2), 2)); Remember that you need to declare a local variable named distance in the beginning of this function, and don t forget to return this value using a return statement as the last line of this function. In the Display_Output function, echo back the two ordered pairs, and give the distance between them. All of these should be displayed to one decimal place using the setprecision command at the beginning of this function after the variable declaration. 10) After the last function implementation of this program, end your program with two comment lines of equal signs. This signifies the end of your source code. For Example:

When you are finished with your program, have tested it thoroughly to make sure that your program is correct, and are sure that you don t need to make any changes, then save your program in the W network mapping, and the Program 11B folder.