1 Advanced Programming Examples. using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Flow of Control Usually the order of statement execution through a method is linear: one after another flow of control: the order statements are executed.
Computer Programming Lab(7).
Execute Blocks of Code Multiple Times Telerik Software Academy C# Fundamentals – Part 1.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 11/8/06CS150 Introduction to Computer Science 1 More Functions! page 343 November 8, 2006.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
C#: Statements and Methods Based on slides by Joe Hummel.
Advanced Programming LOOP.
Recursive. 2 Recursive Definitions In a recursive definition, an object is defined in terms of itself. We can recursively define sequences, functions.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Question 1a) What is printed by the following Java program? int s; int r; int i; int [] x = {4, 8, 2, -9, 6}; s = 1; r = 0; i = x.length - 1; while (i.
1 Programming 2 Overview of Programming 1. Write the equations in C++ notation : a) R =   a + b  24  2 a  b) W = a 12 + b 2 – 2abcos(y) 2a.
Productivity. Calculating productivity Total output Total input Chocolate wave factory has 3000 waves 10 workers 300 waves per worker.
1 Programming Application Overview of Structure Programming.
Dec Important Steps 1. Precise Specification What does the method do? What are the preconditions? 2. Write the base case What is the most basic.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
Chapter 10 Arrays. Learning Java through Alice © Daly and Wrigley Objectives Declare and use arrays in programs. Access array elements within an array.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
C# Programming Methods.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Three kinds of looping structures The while loop The for loop The do (also called the do-while) loop All have equivalent power, e.g., if you can write.
The if…else Selection Statement
CSC111 Quick Revision.
Introduction to Computer Algorithmics and Programming Ceng 113
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
while Repetition Structure
CSC1401 Input and Output (and we’ll do a bit more on class creation)
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Chapter 10 Arrays.
Chapter 2 Elementary Programming
C++ Programming: CS150 For.
Computer Programming Methodology Input and While Loop
Objective: To Divide Integers
TK1114 Computer Programming
Chapter 10 Arrays.
Functions Used to write code only once Can use parameters.
Chapter 6 Arrays.
Computing Adjusted Quiz Total Score
March 29th Odds & Ends CS 239.
Java Fix a program that has if Online time for Monday’s Program
The for-loop and Nested loops
Advanced Programming Lecture 02: Introduction to C# Apps
CSC215 Homework Homework 04 Due date: Oct 14, 2016.
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Multiplication of decimals
AP Java Review If else.
Java Fix a program that has if Online time for Monday’s Program
class PrintOnetoTen { public static void main(String args[]) {
AP Java Review If else.
Multiplication of decimals
CSC 1051 – Data Structures and Algorithms I
Question 1a) What is printed by the following Java program? int s;
Multiplication of decimals
loops revisited I/O arrays
Presentation transcript:

1 Advanced Programming Examples

using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d == a) || (a < b+c) && (d-c <= b)); } 2

A factory has some workers and it divides its workers into three skill levels. Unskilled workers receive L.E per hour, semiskilled workers receive L.E an hour, and skilled workers L.E an hour. Write a program to calculate the worker’s weekly pay formatted to two decimal places. Your program input should consist of the hours worked and a skill level indicator for the worker. Then the wage should be displayed.

for (int N = 1; N < 10; N++) { if ( N % 2 == 0) MessageBox.Show (“X”); else if ( N % 3 == 0) MessageBox.Show (“Y”); else MessageBox.Show (“Z”); } MessageBox.Show(“End”);

Write a C program that reads in 30 integer numbers and then print out their sum and average

int a = 5; int b = 10; a = a + 5; { int a; a = 20; b = b + 5 ; } MessageBox.Show(a+ " " + b) } 6

Write a program that reads 100 integer numbers, determines how many positive and negative values have been read, and computes the average of the input values.

The value that printed is int delta = 0, x = 3; if (x / 2 = = 1) delta = delta + x; x - -; if (x / 2 = = 0) delta = delta + x; x - -; MessageBox.Show(delta);

int p, d=4, a=20; if ((d==4) && (a>24)) { p=d+a; MessageBox.Show( “ Low Risk \n ” );} else { p=a-d; MessageBox.Show( “ Low Risk \n ” );} MessageBox.Show( “ the p is = “+ p); Trace

int I = 12, J = 0; while ( I > 8) { I = I -1; J = J + I; } MessageBox.Show( I+”\t”+J);

Trace length = 10; count = 2; while ( count < 5 ) { if ( length >= 10 ) length = length – 2; else length = length * count; count++; } MessageBox.Show( “ The length is ” + length);

int x=2, y=2, k=1; do { y = y * x; MessageBox.Show(“k = k+ “y=“+ y); y = y – k; MessageBox.Show(“k = k+ “y=“+ y); k = k + 1; } while (k < 4);

String a = "alfred"; String b = "fred"; b = "al" + b; if (a == b) a = "fred"; else b = "fred"; 13