And c++?. What will we do? C vs JAVA Dev-C++ tutorial and your first program C++ structure Reading input/output Flow Control (if, for, while) array function.

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
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.
Basic Java Constructs and Data Types – Nuts and Bolts
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Programming
Introduction to Programming
Methods and Formatted Output Chapter 4. Overview Breaking down a big program into small methods. Formatting output – using printf – using DecimalFormat.
Chapter 8: Arrays.
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 {
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
C Language.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer Programming Lab(7).
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Q1 Review. Other News US News top CS Universities global-universities/computer- science?int=994b08.
Air Force Institute of Technology Electrical and Computer Engineering
By Senem Kumova Metin 1 DATA TYPES. by Senem Kumova Metin 2 DATA TYPE? …… x; // DECLARATION OF VARIABLE X printf(“Do you want to go on? \n”) printf(“Please.
CS110 Programming Language I
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Sort the given string, without using string handling functions.
CS1010 Programming Methodology
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
COMP1180 Review Date: 4 March, 2009 Time: 10:30am - 12:20pm Venue: –CS students -- FSC801C and FSC801D –IS and other students -- OEE1017 Remarks: – 1)
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
1 CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, , 2.6, 3.1, 5.1, , , , Ch. 8 ; Programming.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
#include int main(void) { printf("Hello, world!\n"); return 0; } entry point called on program start only one main( ) in any program # for preprocessor.
 2000 Prentice Hall, Inc. All rights reserved Arrays Array –Group of consecutive memory locations –Same name and type To refer to an element, specify.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Miscellaneous topics Chapter 2 Savitch. Miscellaneous topics Standard output using System.out Input using Scanner class.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
Khalid Rasheed Shaikh Computer Programming Theory 1.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Functions & Pointers in C Jordan Erenrich
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
By Mr. Muhammad Pervez Akhtar
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
Gramming An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Simple Console Output CS 21a. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
A bit of C programming Lecture 3 Uli Raich.
Command Line Arguments
Introduction to C CSE 2031 Fall /3/ :33 AM.
Lecture Note Set 1 Thursday 12-May-05
OUTPUT STATEMENTS GC 201.
CS 2308 Exam I Review.
An Introduction to Java – Part I, language basics
AKA the birth, life, and death of variables.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Java for Beginners University Greenwich Computing At School DASCO
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Fundamental Programming
EE 312 Exam I Review.
EE 312 Exam I Review.
Presentation transcript:

And c++?

What will we do? C vs JAVA Dev-C++ tutorial and your first program C++ structure Reading input/output Flow Control (if, for, while) array function (method) debugging

Hello World (Day 1 Morning) C JAVA import java.io.*; class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } import java.io.*; class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } #include int main(int argc, char* argv[]) { printf("Hello, CP!\n"); return 0; } #include int main(int argc, char* argv[]) { printf("Hello, CP!\n"); return 0; }

C vs JAVA C code DOES NOT need to be in a class No filename restriction C and JAVA have very similar syntax if, for, while is the same Data type is almost the same (int, char, bool, float, double, etc) Function and method is the same For c++, function does not need to be in a class We don’t really use any class in algorithm :D

Output (printf) printf(format_string, value…); commandWhat you get printf(“YES”);YES printf(“YES %d”,12);YES 12 printf(“%d is more than%d”,24,12);24 is more than12 printf(“floating point %f”,2.3457);floating point printf(“test\ntest\nhaha”);test haha printf(“string %s is possible”,”haha”);string haha is possible

input(scanf) scanf(format_string, &variable…); Use the same format string #include int main() { int age, w; printf("Please enter your age and weight”); scanf("%d %d", &age, &w); printf(“your age = %d \n your weight is %d\n”,age,w); }

Condition Statement If statement The same as java #include int main() { int age; printf( "Please enter your age" ); scanf( "%d", &age ); if ( age < 100 ) { printf ("You are NOT old!\n" ); } else { printf ("You are old!\n" ); } return 0; } #include int main() { int age; printf( "Please enter your age" ); scanf( "%d", &age ); if ( age < 100 ) { printf ("You are NOT old!\n" ); } else { printf ("You are old!\n" ); } return 0; }

While loop The same as java #include int main() { int x = 0; while ( x < 10 ) { printf("x = %d\n",x); x++; } return 0; } #include int main() { int x = 0; while ( x < 10 ) { printf("x = %d\n",x); x++; } return 0; }

For loop The same as java #include int main() { for (int i = 0;i < 10;i++) { printf(“i = %d\n",i); } return 0; } #include int main() { for (int i = 0;i < 10;i++) { printf(“i = %d\n",i); } return 0; }

Practice Lab 1 ( Prob 0,1 Lab 2 ( Prob 0,1 hw00e (BMI) hw00c (drawbox) f hw00d (time after) f

Array in C++ (Day 1 Afternoon) (almost) the same as java #include int main() { int fibo[100]; fibo[0] = 1; fibo[1] = 1; for (int i = 2;i < 100;i++) { fibo[i] = fibo[i-1] + fibo[i-2]; } printf("%d\n",fibo[99]); return 0; }

2D Array Example #include int main() { int x; int y; int array[8][8]; for ( x = 0; x < 8; x++ ) { for ( y = 0; y < 8; y++ ) array[x][y] = x * y; } printf("Array Indices\n"); for ( x = 0; x < 8;x++ ) { for ( y = 0; y < 8; y++ ) printf("[%d][%d] = %d\n",x,y,array[x][y]); printf("\n"); } return 0; } #include int main() { int x; int y; int array[8][8]; for ( x = 0; x < 8; x++ ) { for ( y = 0; y < 8; y++ ) array[x][y] = x * y; } printf("Array Indices\n"); for ( x = 0; x < 8;x++ ) { for ( y = 0; y < 8; y++ ) printf("[%d][%d] = %d\n",x,y,array[x][y]); printf("\n"); } return 0; }

More practice Lab 2 Prob 2 hw00f

Debugging (Day 2 Morning) Follow guide in Lab 3 (