CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

Similar documents
CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)

CISC 181 Lab 2 (100 pts) Due: March 7 at midnight (This is a two-week lab)

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

CISC 181 Lab 2 (100 pts) Due: March 4 at midnight (This is a two-week lab)

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5.

Boolean Expressions. Is Equal and Is Not Equal

Boolean Expressions. Is Equal and Is Not Equal

These are notes for the third lecture; if statements and loops.

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

Lesson 2 Variables and I/O

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

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

Intro. Scheme Basics. scm> 5 5. scm>

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

CS 142 Style Guide Grading and Details

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

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

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

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

Unit 7. 'while' Loops

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

My First Command-Line Program

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

Introduction to Programming Style

Divisibility Rules and Their Explanations

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

4. Structure of a C++ program

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

Chapter 17 - Notes Recursion

CSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions. User Defined Functions

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Solving Problems Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

VARIABLES & ASSIGNMENTS

Lecture 4 CSE July 1992

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

Computer Programming : C++

Computer Science II Lecture 1 Introduction and Background

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

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

4. Java Project Design, Input Methods

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

Tips from the experts: How to waste a lot of time on this assignment

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

Chapter 2. C++ Basics

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

Introduction to L A TEX for MCS-236

Enums. In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed.

CS 1110, LAB 1: PYTHON EXPRESSIONS.

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

Lab 6 Vectors and functions

Table of Laplace Transforms

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

QUICK EXCEL TUTORIAL. The Very Basics

More Complex Versions of the if Statement. Class 13

Week 1: Hello World! Muhao Chen

The C++ Language. Arizona State University 1

QUIZ. What are 3 differences between C and C++ const variables?

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

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

Ex: If you use a program to record sales, you will want to remember data:

Lab 4: Strings/Loops Due Apr 22 at midnight

pointers + memory double x; string a; int x; main overhead int y; main overhead

CpSc 1111 Lab 5 Formatting and Flow Control

printf( Please enter another number: ); scanf( %d, &num2);

Something we should know

Lecture 1: Overview

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

C++ for Java Programmers

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

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

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

The compiler is spewing error messages.

Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors

Math Modeling in Java: An S-I Compartment Model

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++

Engineering Tools III: OOP in C++

Installing and Using Dev-C++

Introduction to C ++

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

C++ For Science and Engineering Lecture 2

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013

Getting Started with Visual Studio

How to approach a computational problem

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

Stage 11 Array Practice With. Zip Code Encoding

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

8. The C++ language, 1. Programming and Algorithms II Degree in Bioinformatics Fall 2017

assembler Machine Code Object Files linker Executable File

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

Transcription:

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) Problem 0: Install Eclipse + CDT (or, as an alternative, Netbeans). Follow the instructions on my web site. Note that if you don t still have java installed on your computer, you will have to install it as well. Both Eclipse and Netbeans require Java. From D. Sorenson: On Macs, you may need to open a terminal window and type in the command, "xcode-select --install". Formatting Rules: You want your code to be as easy and clear to read as possible for your partner, other programmers, your TA, and me. We reserve the right to take off points for code that works but is difficult to read. Programmers all use pretty much the same formatting rules, making code easier to follow. At this point I expect your code to be formatted properly. Function comments (defined below) must be written before you write the function code. We will not help you with code unless you have the function commented properly Comments: ALL code should be commented. Comments you should include: 1. Every file should start with your name, possibly your partner(s) s name, the date, and what the file holds in general. 2. A.Every function should state what type and what purpose the input parameters have, what is being returned from the function (again, both type and purpose), and the function s purpose. The goal of these comments are so that someone who never sees your function can call it properly and use the returned result properly. b. if function definitions and declarations are in the same file, you may include comments for the function definitions alone. If, however (and we will do this in future labs) the function declarations and function definitions are in different files, comments for the function should be in both places. The function definition comments should have a bit more information about the guts of the function (i.e., how it actually works) whereas the function declaration comments will probably be shorter and focus on what the input values and results are. 3. If there is any tricky, unusual, or difficult to read code within your function, that should be commented. As much as possible, though, with good variable names and clean code, your code should be fairly readable without comments. 4. While not required, inside the function it often helps to indicate what a closing squiggly bracket closes, e.g.,: int x = 3; if (x > 5) { cout << large << endl; // if (x > 5) 1

// main Formatting: (aka indenting and where to put the squiggly brackets) When coding, I expect you to use a systematic form. This means that the opening squiggly may or may not be on the same line as the function or condition it opens, but the closing squiggly bracket should be on its own line and vertically aligned with the beginning of the code it opened, e.g., //main Or Int main() { //main Everything inside the squiggly brackets should be indented consistently, e.g.,: int x=3; int y=10; for (;x<y;x+=2) { cout << x << endl; //for //main DO NOT place more than one programming instruction on the same line (yes, you can do it. Don t do it). E.g., the following is not formatted properly, although it will compile: if (x < 3) { cout << hi << endl; //bad! Equally, the following is bad form: Naming: int x = 3; int y = 4; int z = x + y; cout << z << endl; //bad bad bad!!! Function names and variables should start with small letters. If the function or variable name consist of more than one word, there are two formats that are conventional: 1. Camel case, e.g., datastructures(), getvalues() etc. or 2. Underscore, e.g., placing a _ between words, e.g., data_structures(), get_values(). Whatever of these you prefer is fine, but be consistent. Boolean Functions: If a function returns a Boolean variable, it is convention to name the function with the first word of is, e.g., isdivisiblebythree() (or is_divisible_by_three() ) for a function that returns a Boolean value indicating whether a number is divisible by 3. Constants can either be defined with the first letter being capitalized or the entire thing being capitalized, e.g., #define Pi 3.1415 #define MIN(X,Y) ((X) < (Y)?(X):(Y)); 2

It is more typical to capitalize the entire constant. Please follow these formatting conventions when writing code for this class. More formatting conventions will follow. Equally, your TA has the right to require specific formatting rules in order to make his/her grading experience easier. Pay attention to these rules! Programming Problems: Note: At this point in the semester you will be using one file. The file will start with comments including you and your partner s names, your TA s names, the date, and the lab (lab 1). It will then have your include files, and then it will have your function declarations (with the function definitions below your main function), followed by your main function, whose sole purpose is to call your functions for each problem, and then under the main function you will have your function definitions, in the order in which they occur for this lab. So your file should look something like this (date and time don t have to look exactly like this I know eclipse automatically inserts the date in a different way and that s fine): /* Debra Yarrington * TA s name * 2/14/17 * This file contains functions for lab 1. The functions aren t necessarily related * in any way other than that they are required for lab 1. */ #include <iostream> #include <stdlib.h> using namespace std; int func(int k[]) ; //function declaration //call functions here return(0); int func(int k[]) { //function definition int a = 0; for (int i = 0; i < 4; i++) { a += k[i]; return a; 3

Note: For each problem except problems 1, the Collatz conjecture problems, and the leap year problem, call the function created 3 times in your main function with 3 different input parameters (with a comment next to it of the expected output parameter. After the 3 test calls for a particular function, print out a line of **************************************** and then Problem x on the next line, so the TA can clearly see where each problem s output starts and stops. *********************************************************************************** Problem 1. (2 pts) In your main function, print out Hello World!. If you can get this to work, we ll know you ve gotten a c++ compiler to work correctly on your computer. Problem 2: (3 pts) Write a c++ function that takes as input parameter an integer. The function uses a while loop to determine whether that number is a prime number or not, and returns True if it is, and False otherwise. Problem 3: (3 pts) Write a function that takes 2 integers as input parameters and uses a loop to calculate the sum of all the numbers between the first and second number. Note that the first number may or may not be less than the second number. The function returns the sum. Problem 4 (4 pts): The Collatz Conjecture states that, given any positive natural number, you will always eventually reach 1 if you follow the following formula: if the number is even, divide by 2, and if the number is odd, multiply by 3 and add 1. Continue the process indefinitely or until the number is equal to 1. This problem has never been proven, and someone did actually prove that a generalization of the problem is unprovable. That said, no one s found an exception either. Write a program that asks the user to input a natural positive number. Then follow the above formula until the number is equal to 1. Count how many times you loop, and write that out to the console window. Return the count of how many times the Collatz Conjecture had to loop Problem 5 (4pts): To determine whether a year is a leap year, you use the following rules (I googled this): 1. If the year is evenly divisible by 4 go to step 2. Otherwise go to step 5: 2. If the year is evenly divisible by 100, go to step 3. Otherwise go to step 4: 3. If the year is evenly divisible by 400, go to step 4. Otherwise go to step 5: 4. The year is a leap year (which, oddly, means it has an extra day, or 366 days). 5. The year is not a leap year (which means it has 365 days Now you know how to calculate a leap year. I m thinking step 3 isn t going to come in handy for most of us. That said, write a function that calculates all the leap years for the next 400 years and prints them out (starting with 2017, which won t be printed out). This problem should return nothing. It should print out the leap years as it loops. Problem 6 (5 pts): Write a program takes an integer as an input parameter, and then, if the number is 5, for example, prints out the following to the console window: 4

* Note that if the user enters an even number, round up to the next odd number. Problem 7 (4 pts): Copy the program in problem 4 and modify it so that it is a function that takes as input parameters two integers, assuming the first is smaller than the second number. Continue modifying the function so that for every number between the first number and the second number (assume the first number is less than the second number), the number is printed out, and then it is tested with the Collatz Conjecture. If the loop results in a 1 the program should print out, Collatz Conjecture is still working. (Now, if it doesn t, the Collatz conjecture will loop infinitely and your program will hang. You should write down the numbers you sent in, because you just did something really amazing and found a number that doesn t work with the Collatz conjecture. Or you did something wrong. You decide which is more likely). This function should return nothing. To Turn In: The.cpp file (with the names of everyone in your group) containing the main function containing test cases for each of the functions, followed by each of the functions. 5