First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio

Similar documents
First Visual Basic Lab Paycheck-V1.0

Program Organization and Comments

ROCK PAPER SCISSORS Rock Paper Scissors Lab Project Using C or C++

Add Subtract Multiply Divide

Chapter 1 - What s in a program?

Chapter Two MULTIPLE CHOICE

Understanding main() function Input/Output Streams

Lab: Supplying Inputs to Programs

C++ Support Classes (Data and Variables)

My First Command-Line Program

Data Types Literals, Variables & Constants

Fundamentals of Programming Session 4

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

Should you know scanf and printf?

Getting started with C++ (Part 2)

Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร

Chapter 2 C++ Fundamentals

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

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

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

UEE1302 (1102) F10: Introduction to Computers and Programming

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

EE 109 Lab 8a Conversion Experience

Programming with C++ as a Second Language

Chapter 2. C++ Basics

BOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT. Problem Solving with Computers-I

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.

BITG 1233: Introduction to C++

Sequential Program Execution

Installing and Using Dev-C++

Chapter 3: Input/Output

Chapter 2: Basic Elements of C++

Scientific Computing

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

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

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

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

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

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Computer Programming : C++

4*4*4 2. What is the output of the following flowchart for the values given below: (25 p)

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

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

Chapter 1 Introduction to Computers and C++ Programming

Expressions, Input, Output and Data Type Conversions

Tutorial 2: Compiling and Running C++ Source Code

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

Your First C++ Program. September 1, 2010

The C++ Language. Arizona State University 1

Spring 2017 CMSC 140 Programming Project 7: Payroll

Unit 7. 'while' Loops

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Programming. C++ Basics

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Maciej Sobieraj. Lecture 1

(4-2) Selection Structures in C H&K Chapter 4. Instructor - Andrew S. O Fallon CptS 121 (September 12, 2018) Washington State University

Using Microsoft Excel

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

assembler Machine Code Object Files linker Executable File

Programmazione. Prof. Marco Bertini

CSCI 1061U Programming Workshop 2. C++ Basics

Introduction to Programming

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

Relational Operators EXAMPLE. C++ By

Sample Code: OUTPUT Daily Highs & Lows

Lab 1: First Steps in C++ - Eclipse

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

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

LAB #8. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

CE221 Programming in C++ Part 1 Introduction

This watermark does not appear in the registered version - Slide 1

Week 1: Hello World! Muhao Chen

CpSc 1111 Lab 9 2-D Arrays

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

Chapter 1: Why Program? Computers and Programming. Why Program?

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

CSCI-1200 Data Structures Spring 2015 Lecture 2 STL Strings & Vectors

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

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

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

Objectives. In this chapter, you will:

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

Introduction to C++ Introduction to C++ 1

CPE 101. Overview. Programming vs. Cooking. Key Definitions/Concepts B-1

Data Types Literals, Variables & Constants

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

Week 2: Data and Output

CSCE 121 ENGR 112 List of Topics for Exam 1

Algorithms for Programming Contests - Week 1

1. C++ Overview. C++ Program Structure. Data Types. Assignment Statements. Input/Output Operations. Arithmetic Expressions.

Pre Lab (Lab-1) Scrutinize Different Computer Components

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Transcription:

C & C++ LAB ASSIGNMENT #1 First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio Copyright 2013 Dan McElroy Paycheck-V1.0 The purpose of this lab assignment is to enter a C or C++ into Visual Studio and make it work. You can choose to create the project using either C or C++, or both, but you only get credit for one project. All of the program code is already provided for you. You only need to create the project, enter the code, test the program and write the lab report. As the course progresses, you will be required to create the entire project. 1

Paycheck-V1.0 This presentation is in three parts: 1) Project Definition Discussion of the project and what is to be done. 2) Microsoft implementation in C or C++ Detailed description on how to enter your first program on the computer using Microsoft Visual Studio and make it work. 3) Project Documentation Description of how to submit your lab report. 1 - Project Definition Design a program using C or C++ that does the following: 1) Read the number of hours worked and the pay rate 2) Compute the pay including overtime at time-and-a-half 3) Display the gross pay, not including taxes or any other deductions. 2

2 - Paycheck Develop Algorithm Develop an algorithm in pseudo-code. Use a HIPO (Hierarchical Input Process Output) chart to define the input, process and output for the program. INPUT PROCESS OUTPUT Hours PayRate Read Hours from keyboard Read PayRate from keyboard Determine RegularHours (up to 40) Determine OvertimeHours (hours over 40) RegularPay = RegularHours * PayRate OvertimePay = OvertimeHours * PayRate * 1.5 GrossPay = RegularPay + OvertimePay Display GrossPay GrossPay 3 Outline What the Screen Should Look Like When the Program Runs 3

4 Convert the Algorithm into Code The #include files go here. The include files will be different for C and C++. They help the compiler build the program. The request for input (prompt) and keyboard input go here. The C language uses the printf and scanf functions for output and input. C++ uses cout and cin. The code to display the amount of the paycheck goes here. The C language uses printf and C++ uses cout. C and C++ Input and Output Routines C Language Input/Output scanf formatted input scan pronounced Scan-F printf print formatted pronounced Print-F (old computer terminals were printing TeleTypes) C++ Language Input/Output cin Console IN-put pronounced See-In (not like SIN ) cout Console OUT-put pronounced See-Out (not KOWT ) 4

5 Test the Program Since this program can process a paycheck that does not have overtime (40 hours or less), and also a paycheck that has overtime (more than 40 hours), it is important to test both conditions. It also important to test the program at 40 hours. For example, use these values: 6 Document the Project A text document for the lab report is provided. Most of the lab report for this first project is already filled in. You need to complete the rest of the report. 5

Implementation Using Microsoft Visual Studio O Start Visual Studio O Open a New Project, name it Paycheck-V1.0 O Enter the program O Test the program with multiple inputs Your First C or C++ Program Although it may seem difficult to get the first program to work using Microsoft Visual Studio, it becomes much easier after you have done it a few times. Since this is your first C or C++ program, the steps are very detailed. Make sure you read each of the directions carefully and don t move to the next step until you have completed the current step. Microsoft Visual Studio works easiest with C++. There is a few extra steps that are required to get Visual Studio to compile a program in the C language. 6

Start Visual Studio Start Visual Studio and select New Project Set the Project Name Set the Project Name and Location where you want it stored on the disk 7

Click the Finish Button An Empty Project 1 2 3 Your project should look like this after: 1) Click View, on the menu bar, select Solution Explorer 2) Click the name of the project 3) Click Source Files 8

If You Are Writing a C Program Microsoft Visual Studio comes configured to develop C++ programs. You will need to make a few changes to successfully develop a C program. 1) Change the file extension of the program to.c instead of.cpp 2) Delete the #include "stdafx.h" line 3) Change the line that has int _tmain from: int _tmain(int argc, _TCHAR* argv[]) to: int main(int argc, char* argv[]) 4) Turn off Precompiled Headers These changes are described in more detail in the next slides. Change the File Extension for C Programs Delete #include "stdafx.h" These steps are not necessary for C++ programs For C programs, right-click the name of your program. Change the file extension from.cpp to.c For C programs, delete the line that has #include "stdafx.h This line may not appear in all versions of Microsoft C++, and will not appear in any non-microsoft C++ 9

Change the int main Line for C Programs This step can be done for either C or C++ programs For C programs, change: int _tmain(int argc, _TCHAR* argv[ ]) to: int main(int argc, char* argv[ ]) The second version of int main( will work for all versions of C and C++. Turn Off Precompiled Headers for C programs 1) View Solution Explorer Ctrl-Alt-L 2) Open the Properties Page by clicking the mouse inside the Solution Explorer area OR pressing Alt+Enter 3) Expand the C/C++ options by clicking the tiny arrow next to C/C++ 4) Click Precompiled Headers, and then click the down-arrow on the right 5) Select Not Using Precompiled Headers This step is not necessary for C++ programs 10

Enter the Code for the C or C++ Program C C++ Get a copy of the C or C++ program from Moodle Notes on the Paycheck Program 1/4 Be very careful when typing computer programs. 1. Except for comments, C and C++ are case sensitive, which means that upper-case letters (A-Z) are treated completely differently from lower-case letters (a-z). 2. Do not put spaces in the middle of variable names. Example: OvertimePay has no spaces. 3. Watch the placement of the semicolon ; character. It does not appear at the end of every line. 4. Use \n for C programs and endl for C++ programs. The \n uses a backslash \ not a forward slash /. The endl stands for end-of-line and the last character is a small-l, not the number 1. 5. Pay close attention to the parentheses ( ), the curly braces { } and the angle brackets < > 11

Notes on the Paycheck Program 2/4 TITLE BLOCK Include a block of comments that identify the name of the file, your name, date, and inputs and outputs used by the program. C /* Paycheck-V1.0.c Dan McElroy January 20, 2014 CIS-54 C/C++ Programming Inputs: Hours, PayRate Outputs: Paycheck */ C++ // Paycheck-V1.0.cpp // Dan McElroy // January 20, 2014 // CIS-54 C/C++ Programming // Inputs: Hours, PayRate // Outputs: Paycheck C style comments use a /* to start the comment, and */ to end the comment. A comment can either be on one line or it can span several lines. It can be used in C++. C++ style comments start with // and stop at the end of the line. C++ style commends cannot cover multiple lines. Most of the modern C compilers will also accept C++ style comments. Notes on the Paycheck Program 3/4 INCLUDE FILES The compiler uses header files that are read into your program with the #include statement. You may need to include multiple header files depending on which routines you use in your program. C #include <stdio.h> C++ #include "stdafx.h // Only Microsoft #include <iostream> #include <iomanip> using namespace std; C programs need to include stdio.h to provide access to printf and scanf. NOTE: stdio.h is pronounced as individual letters: S-T-D-I-O-dot-H Do not pronounce it as one word STUDIO. It is not a dance or art studio. C++ programs need to include iostream to use cin and cout. The iomanip include file is needed for cout to format the output for the number of digits past the decimal. The using namespace std is needed for iostream and iomanip. The stdafx.h is used only by some versions of Microsoft. 12

Run and Test the Program Press Ctrl-F5 to run the program. If you select the Debug menu and click Start Debugging or just press the F5 key, the program will run but the output screen will disappear as soon as the program finishes and you won t be able to see the output screen. Verify That the Program Produces Correct Results with and without Overtime 13

Project Documentation and Lab Report A text document for the lab report is provided. Most of the lab report for this first project is already filled in. The lab report is a two page document. You need to complete the rest of the report that is shown in red text. Lab Report Document Page 1 On Moodle, click the link: Paycheck V1.0 Lab Project and Report The lab report document is named C-Paycheck-Lab.doc Complete the lab report by replacing the red text with your report. Save the file with a new name. Submit your own lab report, not a copy of someone else s report. Page 2 14

Submit Your Work on Moodle All of your lab assignments should be submitted using Moodle. Make sure you click the correct link on the class Moodle page for your assignment, select the file you want to upload, click the Upload button and verify that the file was sent. Detailed instructions follow. 1. Find the Correct Submit Link In this example, submit the C or C++ Payroll lab report. Click the link, Submit the Paycheck V1.0 Lab Report 15

2. Submit Your Assignment Moodle will load a new screen with instructions, a due date and the Add submission button. Verify that you will be submitting your report to the correct location then click the Add submission button. 3. Choose to File to Be Submitted Moodle then displays the File submissions screen. You can either: 1) Use the mouse to drag your completed lab report on top of the big blue arrow (works with most browsers), or 2) Click the Files link and find the file on your computer. After you have selected the file, click the Save changes button 16

4. Verify That the File Was Uploaded If your file name shows up here, then the instructor can see the file. If you want to view the status of your submission, go back to the Submit your Report link on the Moodle class web page. If you want to update and resubmit your lab report before it has been graded, click the Edit submissions button. Your old submission will be deleted an be replaced with the updated version. Congratulations! Congratulations on completing your first C or C++ assignment. Refer back to this lab assignment when working on future labs for instructions on creating a C or C++ program using Microsoft Visual Studio, and instructions on how to upload a file to Moodle. 17

ACKNOWLEDGEMENTS COMPILER SCREEN SHOT Microsoft Visual Studio VIDEO EDITING SOFTWARE Roxio Creator TM NXT Pro 2 18