CS1101: Programming Methodology Preparing for Practical Exam (PE)

Slides:



Advertisements
Similar presentations
 2005 Pearson Education, Inc. All rights reserved Introduction.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C Programming
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Pseudocode and Algorithms
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
18 File handling1June File handling CE : Fundamental Programming Techniques.
Computer Science 1620 Programming & Problem Solving.
Introduction to C Programming
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
The break and continue statements. Introduction There are 2 special statements that can affect the execution of loop statements (such as a while-statement)
CS1101: Programming Methodology Aaron Tan.
CS1101: Programming Methodology
Java Programming: From the Ground Up
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
By the end of this session you should be able to...
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
CS1101: Programming Methodology Aaron Tan.
Week 6.  Lab 1 and 2 results  Common mistakes in Style  Lab 1 common mistakes in Design  Lab 2 common mistakes in Design  Tips on PE preparation.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
CS1101X: Programming Methodology Recitation 6 Arrays I.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 12/11/20151.
CS1101X: Programming Methodology Recitation 4 Design Issues and Problem Solving.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Simple algorithms on an array - compute sum and min.
CS1101: Programming Methodology Preparing for Practical Exam (PE)
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Efficiently Solving Computer Programming Problems Doncho Minkov Telerik Corporation Technical Trainer.
1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.
CS1010: Programming Methodology Preparing for Practical Exam (PE)
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
CS1010: Programming Methodology
CS 116 Object Oriented Programming II Lecture 4 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
CS1101X: Programming Methodology Recitation 6 Arrays I.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CSC111 Quick Revision.
CS1010: Programming Methodology Preparing for Practical Exam (PE)
Repetition-Counter control Loop
Chapter 4 – Control Structures Part 1
Building Java Programs
1) C program development 2) Selection structure
Suppose I want to add all the even integers from 1 to 100 (inclusive)
EECE.2160 ECE Application Programming
Computer Science Club 1st November 2019.
Presentation transcript:

CS1101: Programming Methodology Preparing for Practical Exam (PE)

CS1101: Preparing for PE2 Important Notes (1/2) Have you been practising? In a simulated test environment? Manage your time well. Read the instructions carefully. Read the questions carefully. When in doubts, ask. Do not start coding right away. THINK about the algorithm first. Check that your algorithm works before you start coding.

CS1101: Preparing for PE3 Important Notes (2/2) If the problem seems hard, simplify it, break it into smaller sub-problems. In the worst case, solve a simplified version. A partial program is better than no program. Make sure that your programs can be compiled. Code incrementally. Test your programs thoroughly with your own test data. Your programs will be graded manually. CourseMarker is just a tool.

CS1101: Preparing for PE4 Other tips… Two questions. Spend 20 – 30 minutes on thinking, algorithm, etc. before you code. Do not forget to add appropriate comments and proper indentation in your codes. These are graded as well. Ask your lecturer!

CS1101: Preparing for PE5 Task 1: Plurals (1/5)  If a word ends in “ y ”, replace it with “ ies ”.  If a word ends in “ s ”, “ ch ” or “ sh ”, add “ es ”.  All other cases, just add “ s ”.  Input consists of multiple lines. Each line contains one word. Each word contains one or more lowercase letters.

CS1101: Preparing for PE6 Task 1: Plurals (2/5) Enter a word: dairy The plural form of "dairy" is "dairies". Enter a word: boss The plural form of "boss" is "bosses". Enter a word: dish The plural form of "dish" is "dishes". Enter a word: bird The plural form of "bird" is "birds". Enter a word:

CS1101: Preparing for PE7 Task 1: Plurals (3/5) while ( there is still input ) { read str; n = str.length(); if (str ends with “y”) print str.subString(0, n-1) + “ies”; else if (str ends with “s” or “ch” or “sh”) print str + “es”; else print str + “s”; }

CS1101: Preparing for PE8 Task 1: Plurals (4/5)

CS1101: Preparing for PE9 Task 1: Plurals (5/5)

CS1101: Preparing for PE10 Task 2: Factorisation (1/4) Past PE question Time limit: 30 minutes Write a program to read in a non-zero integer and display the factorisation. Examples: Enter n: 8 8 = 1 * 2 * 2 * 2 Enter n: = -1 * 2 * 2 * 3 * 5 * 5 Enter n: = 1 * 7 * 11

CS1101: Preparing for PE11 Task 2: Factorisation (2/4)

CS1101: Preparing for PE12 Task 2: Factorisation (3/4)

CS1101: Preparing for PE13 Task 2: Factorisation (4/4)

CS1101: Preparing for PE14 Task 3: Candles (1/3) Peter has n candles. He burns them one at a time and carefully collects all unburnt residual wax. Out of the residual wax of exactly k > 1 candles, he can roll out a new candle. How many candles can Peter burn? The input contains two integers giving the values of n and k. The output should consist of just one integer giving the maximum number of candles that Peter can burn.

CS1101: Preparing for PE15 Task 3: Candles (2/3) Sample run: Enter n: 5 Enter k: 3 Number of candles Peter will burn = 7

CS1101: Preparing for PE16 Task 3: Candles (3/3)

CS1101: Preparing for PE17 Task 4: Pascal’s Triangle (1/5) In this problem, you are asked to generate Pascal’s Triangle. Pascal’s Triangle is useful in many areas from probability to polynomials to setting programming questions. It is a triangle of integers with 1 on top and down the sides. Any number in the interior equals the sum of the two numbers above it. For example, here are the first 5 rows of the triangle

CS1101: Preparing for PE18 Task 4: Pascal’s Triangle (2/5) Output for n (number of rows) = 6. Write a program to generate a Pascal’s Triangle as shown. It should be observed that the next row of the Pascal’s triangle can be generated from the previous row. Thus, using a single-dimensioned array to store the values of the previous rows seems appropriate

CS1101: Preparing for PE19 Task 4: Pascal’s Triangle (3/5) import java.util.*; public class PascalTriangle { public static void main (String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter n: "); int n = scanner.nextInt(); int[] pascal = new int[n]; printPascalTriangle(pascal); }

CS1101: Preparing for PE20 Task 4: Pascal’s Triangle (4/5) n =

CS1101: Preparing for PE21 Task 4: Pascal’s Triangle (5/5)

CS1101: Preparing for PE22 Task 5: Teams (1/3) We need to split a group of n (an even number) players into two teams. Here is what we do: Line up the players in a straight line. Stating from the first player in the line, count the players while reciting a song that consists of m words. The m th player leaves the line and joins “Team A”. Repeat the song, now starting with the player who comes after the player who just left. The next player who leaves the line joins “Team B”. Whenever the end of the line is reached, the counting resumes at the beginning of the line. Repeat until all the players are assigned to one of the two teams.

CS1101: Preparing for PE23 Task 5: Teams (2/3) The first 2 lines of the input are the numbers n and m. The next n lines of the input are the names of the players. The input name sequence determines the order in which the players are lined up. Your output should list all the players in “Team A” followed by “Team B” in the order which they joined the respective teams.

CS1101: Preparing for PE24 Task 5: Teams (3/3) Sample input: 6 3 Emily Hannah Emma Ashley Sarah Victoria Sample output: Emma Ashley Sarah Victoria Hannah Emily

CS1101: Preparing for PE25 More tasks at… Visit

CS1101: Preparing for PE26 End of File