Lab01: C++ Expressions ES036a: Programming Fundamentals Fall 2007

Similar documents
Getting Started with Visual Studio

Lab 2.1: Fixing a C++ program

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

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

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

Programming Language. Functions. Eng. Anis Nazer First Semester

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

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

Lab 4: Introduction to Programming

Week 4 EECS 183 MAXIM ALEKSA. maximal.io

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

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

WARM UP LESSONS BARE BASICS

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

After an "Hour of Code" now what?

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.

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas

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

Linux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs

10-2 Circles. Warm Up Lesson Presentation Lesson Quiz. Holt Algebra2 2

SUMMER WORK. Skills Review for Students Entering Geometry or Geometry with Trig

download instant at Introduction to C++

Summer Math Assignments for Students Entering Integrated Math

LAB: INTRODUCTION TO FUNCTIONS IN C++

Lab 1. largest = num1; // assume first number is largest

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

Computer Programming : C++

Your First C++ Program. September 1, 2010

Other operators. Some times a simple comparison is not enough to determine if our criteria has been met.

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

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

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

The C++ Language. Arizona State University 1

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

Lab Instructor : Jean Lai

Understanding main() function Input/Output Streams

Exam 2 Review. 2. What the difference is between an equation and an expression?

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

A First Program - Greeting.cpp

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

Engineering Problem Solving with C++, Etter/Ingber

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

SENIOR HIGH MATH LEAGUE April 24, GROUP IV Emphasis on TRIGONOMETRY

Fundamentals of Programming CS-110. Lecture 2

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.5. for loop and do-while loop

CS31 Discussion 1E. Jie(Jay) Wang Week1 Sept. 30

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

Name ANSWER KEY Date Period Score. Place your answers in the answer column. Show work clearly and neatly. FOCUS ON WHAT IS NECESSARY FOR SUCCESS!

Objectives. In this chapter, you will:

EP578 Computing for Physicists

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

Expressions, Input, Output and Data Type Conversions

Lab # 02. Basic Elements of C++ _ Part1

Chapter 2. Outline. Simple C++ Programs

Chapter 2: Overview of C++

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

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

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

Programming. C++ Basics

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Question 1. [5 points] Circle and briefly explain the error(s) in the following code:

Math-2. Lesson 3-1. Equations of Lines

BITG 1233: Introduction to C++

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

Introduction to Programming

MS Visual Studio.Net 2008 Tutorial

Integrated Math 1: Homework #2 Answers (Day 1)

PIC 10A. Review for Midterm I

Lab 3: Acceleration of Gravity

EP241 Computing Programming

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

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Program Organization and Comments

CHAPTER 2 REVIEW COORDINATE GEOMETRY MATH Warm-Up: See Solved Homework questions. 2.2 Cartesian coordinate system

Integer Data Types. Data Type. Data Types. int, short int, long int

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

2 nd Week Lecture Notes

A SHORT COURSE ON C++

(b) Write a statement that prints the length of the string s (apply appropriate function!):

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

Math 085 Final Exam Review

CSCI 111 Midterm 1 Exam Spring Solutions 09.00am 09.50am, Monday, March 21, 2016

2009 Fall Startup Event Thursday, September 24th, 2009

Lab 9: Creating a Reusable Class

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

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

CS 31 Discussion 1A, Week 1. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50

download instant at Introduction to C++

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

CS 1803 Individual Homework 1 Python Practice Due: Wednesday, January 26th, before 6 PM Out of 100 points

Introduction to Java Applications

Transcription:

Lab01: C++ Expressions ES036a: Programming undamentals all 2007 A. Rationale and Background Welcome to ES036b Lab01. In Lab00 we learned how to create a solution and then a project within this solution in Visual Studio 2005. You are encouraged to revise Lab00. In this lab we will open our existing solution ES036Labs and create our second project Lab01. Please read section G to learn how to do this before doing section E. In this lab you will write your own simple programs by declaring variable and writing simple expressions. Once you complete the lab you will be able to Write and execute a simple C++ program Use cin and cout. Do you own calculation in C++. B. How to Get ull Credit for this Lab You will get credit for your lab when you demonstrate it and get your TA s approval. Submitting your lab online is required. B.1. Submission Instructions Number of files : 2 iles to be submitted : cpp file in E.1 and cpp file in E.2 Rename these files as : your_uwo_user_name_lab01_q1.cpp, your_uwo_user_name_lab01_q2.cpp C. Pre-lab Questions It is important that you read and understand the lab beforehand. Answering the following questions will help. You do not have to submit the pre-lab but be ready for a simple lab quiz. 1. What is the purpose of the function main()in the following code? #include <iostream> using namespace std; int main() { cout<<"welcome to ES036 lab."<<endl; return 0; } 2. Explain the purpose of each line in the above code segment. 3. When do you use cout and cin? 4. How do you declare variables in C++? 5. How do you include comment in C++? 6. What are the variables declared in the following code? #include <iostream> #include <string> Page 1 of 6

using namespace std; int main() { int age; string name; //a variable named age of type int //a variable named name of type string cout<<"tell me your name please: "; cin>>name; cout<<"tell me your age please: "; cin>>age; //prints on screen //waits for keyboard input //prints on screen //waits for keyboard input cout<<"hello "<< name <<" you are "<<age<<" years old."<<endl; } return 0; 7. What is the purpose of the above code? 8. What does the line before the return 0 do? 9. What is the major difference between the data-types int and double? 10. What is the limitation of integer division? D. Good Programming Practice Include comments in your program. Initialize your variables appropriately. E. Lab Questions This is the part that you need to complete to obtain full credit. You will need to submit the cpp files for questions E.1 and E.2. Your TA will ask you questions and request you to do simple modifications. Now we will open our existing solution ES036Labs and create our second project Lab01. Please refer to section G on how to do this. E.1. Question 1: Area of a Circle Requirement: Write a program that calculates and prints the area of a circle, given the radius. Specifications: 1. The program will print a greeting message that describes its mission. 2. It will prompt the user for the radius. 3. It calculates the area and displays the result. See sample output. Hints: You need to add a new project called Lab01 and then add a new item (a cpp file). See instructions in section G to see how to add a new project to an existing solution. 2 The area of a circle is given by A = π r where π 3.1416 and r is the radius of the circle. Sample output: * ES036a-2007 Lab01 Q1 * * Your Name * Page 2 of 6

This program calculates the area of circle when the radius is given. Please enter the radius (cm): 7 The area of a circle with radius 7cm is 153.938 cm^2. Bye bye. Press any key to continue.... E.2. Question 2: Intersection of Two Lines Requirement: Assume that you are given the equations of two lines. y = m1x + c1 and y = m2 x + c2. Write a C++ program to obtain the constants m1, c1, m2 and c2 from the user and calculate the point at which the two lines intersect. Specifications: 1. Program will print a greeting message that describes its mission. 2. It will prompt the user for the constants m 1, c1, m2 and c2. 3. It calculates the area and displays the point at which the two lines intersect. Hints: You need to remove username_lab01_q1.cpp and add a new cpp file: username_lab01_q2.cpp. c The point at which the two lines intersect is given by ( x, y) 2 c1 x = where m1 m2 and c2m1 c1m2 y = m1 m2. Sample Output: * ES036a-2007 Lab01 Q1 * * Your Name * This program finds the intersection of two lines given the slopes and intercepts. Please enter m1: 2 Please enter c1: 1 Please enter m2: 3 Please enter c2: 5 Line y = 2x + 1 intersects with y = 3x + 5 at: (-4, -7). Bye bye. Press any key to continue... Run the program and enter 2 for m 1, 1 for c 1, 3 for m 2 and 5 for c 2. Compare your output with the sample output. What will happen if you enter 2 for m 2 instead of 3?. Additional Questions These problems are for you to practice at home. You do not need to demonstrate or submit them online. Page 3 of 6

a. Write a simple C++ program that would display Hello! on the screen. b. Write a program to print a block using letter, where is 7 characters high and 5 characters wide, as shown below. Can you display your first name in this form? Press any key to continue c. Write a program that prompts the user to enter the speed of a vehicle in miles per hour and display the speed in kilometers per hour where, v miles/h = v kilometers/h x 0.6213712. d. Write a program that prompts the user to input the height and width of a rectangle and then print its area (height x width) and perimeter (2 x height x width) on the screen. e. How can you truncate the result in E.2 to two decimal places (see class notes and/or book)? f. Write a program that would ask the use to input an integer and display the square of the input integer. g. Write a program that would calculate the period of oscillation (in seconds) of a simple T = 2π l pendulum given by the equation g with user input length l (in meters). Assume acceleration due to gravity, g = 9.81 ms 2 and π = 3.1416. Hint: We have to use the sqrt function to calculate the square root. To make this function available, add the following statement: #include <cmath> See page 457 of the textbook for the complete list of math functions that are available. G. Adding a New Project to a Solutions Please read this section before doing section E. We created a solution called ES036Labs in our last lab. This solution contained a project called Lab00. In this assignment, we need to add another project to this existing solution. To do that, we need to reopen the solution. We can do this by opening ES036Labs.sln file. This should be located in H:/ES036Labs if you properly followed the instruction during the last lab. Once you have the solution open, right click on the item at the left panel, as shown in the following figure, and select Add New Project. Please refer Lab00 for the steps to follow. What you need to do is to create and empty Win32Console application as we did in Lab00. Page 4 of 6

Now we need to add a new cpp file. Right click the Lab01 item on the left panel and select Add New Item. Page 5 of 6

orm the dialog that appears (see below), select C++ ile (.cpp). Here you will need to type a name for the new cpp file that you will be creating. Please use the following file naming convention for ES036 labs. username_labxx_qx for example for Lab01, question 1 if your username is wtern, you would use the file name wtern_lab01_q1. Notice that the new file will be located in H:\ES036Labs\Lab01 folder. Before your can run your Lab01, you should set it as the startup project as shown below by right clicking Lab01. Now you know how to add a project to an existing solution. Please return to section E now. Page 6 of 6