Comparison of Batak & C++. Hello world C++ #include int main() { cout << “Hello world\n”; } Batak Program Hello; integer main() { writeline(‘Hello world’);

Slides:



Advertisements
Similar presentations
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Advertisements

Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Functions Prototypes, parameter passing, return values, activation frams.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
CS Nov 2006 C-strings.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Computer Skills2 for Scientific Colleges 1 Pointers in C++ Topics to cover: Overview of Pointers Pointer Declaration Pointer Assignment Pointer Arithmetic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Pointers CSE 2451 Rong Shi.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Strings Do we need to convert integers (or longs, or floats) to strings.
EEL 3801 Part VIII Fundamentals of C and C++ Programming Template Functions and Classes.
6. More on Pointers 14 th September IIT Kanpur C Course, Programming club, Fall
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
Chapter 6: Programmer- defined Functions Development of simple functions using value and reference parameters JPC and JWD © 2002 McGraw-Hill, Inc. Modified.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
1 Pointers and Strings Chapter 5 2 What You Will Learn...  How to use pointers Passing arguments to functions with pointers See relationship of pointers.
String Class. C-style and C++ string Classes C-style strings, called C-strings, consist of characters stored in an array ( we’ll look at them later) C++
Object Management. Constructors –Compiler-generated –The Initializer List –Copy Constructors –Single-arg (conversion ctors) The Assignment Operator.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
FUNCTIONS - What Is A Function? - Advantages Function Declaration
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Strings Chapter 5.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Arrays Chapter 7. Arrays Hold Multiple Values Array: variable that can store multiple values of the same type Values are stored in adjacent memory locations.
Functions. Predefined Functions C++ comes with libraries of code that can be reused in your programs. The code comes in the form of predefined functions.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Prepared by Andrew Jung. Accessing Pointer Data Pointer can be used to access the contents of an array Look at the following syntax: /* Declaration and.
1 Memory, Arrays & Pointers. Memory 2 int main() { char c; int i,j; double x; cijx.
C++ Programming Lecture 18 Pointers – Part II The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
LESSON 06.
Operator Overloading.
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
Data Types.
14th September IIT Kanpur
For Loops October 12, 2017.
Functions I Creating a programming with small logical units of code.
Pointers, Dynamic Data, and Reference Types
CS 2308 Exam I Review.
Functions, Part 1 of 3 Topics Using Predefined Functions
5.1 Introduction Pointers Powerful, but difficult to master
Introduction to Programming
Functions, Part 1 of 3 Topics Using Predefined Functions
Function Overloading.
C Programming Lecture-8 Pointers and Memory Management
Arrays Arrays A few types Structures of related data items
Fundamental Programming
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
Strings …again.
Structure (i.e. struct) An structure creates a user defined data type
Functions, Part 1 of 3 Topics Using Predefined Functions
Functions I Creating a programming with small logical units of code.
Pointers, Dynamic Data, and Reference Types
Functions, Part 2 of 42 Topics Functions That Return a Value
CPS125.
Presentation transcript:

Comparison of Batak & C++

Hello world C++ #include int main() { cout << “Hello world\n”; } Batak Program Hello; integer main() { writeline(‘Hello world’); } No superficial #include directive Hello is an object of type program, explicitly exposed.

Conversion (type casting) C++ int main() { char s1[5] = “32767”; char s2[5] = “65536”; int i = atoi(s1); long l = atol(s2); s1 = itoa(i) s2 = ltoa(l); l = 32767L; float f = (float) i; i = (int) f; } Batak int main() { char[5] s1 := ‘32767’, s2 := ‘65536’; integer i := integer(s1); long l := long(s2); s1 := char[5](i) s2 := char[5](l); l := 32767; float f := float(i); i := int(f); }

Remarks about conversion C++ uses badly named operations (atoi, atol, ltoa, itoa) Programmers have to memorize those names C++ uses different syntax to achieve that (e.g., (int) and atoi) Batak uses properly- named operations (the same name with the target type) Programmers don’t have to memorize additional names Same syntax, conversion is just like calling other operations

Operation prototype C++ void move_to (int old_x1, int old_y1, int new_x1, int new_y1); Batak void move_to (integer old_x1, old_y1, new_x1, new_y1); In C++, programmers have to repeat the name of type in the operation prototype In Batak, they don’t have to C++ void move_to (int x1, int y1, int x2, int y2, char s1[], char s2[]); Batak void move_to (integer x1, y1, x2, y2; char[] s1, s2);

Operation prototype and object declaration C++ void move_to (int x1, int y1, int& x2, int& y2, char s1[], char s2[]) { int a, b; a = x1; b = y1; x2++; y2++; char s3[], s4[]; strcpy(s3, s1); strcpy(s4, s2); } Batak void move_to (integer x1, y1; integer& x2, y2; char[] s1, s2) { integer a, b; a := x1; b := y1; x2++; y2++; char[] s3, s4; s3 := s1; s4 := s2; }

Remark C++ Programmers have to repeat the description of parameter passing for every object, even they are of the same type The syntax of objects list in the operation heading is unnecessarily different from the ones in the operation body Programmers have to memorize name of operation to assign string value; assigning string value is unlike assigning other value. Batak Programmers don’t have to repeat the description of parameter passing, if the objects are of the same type The syntax of object list in the operation heading is only necessarily different (e.g., passed-by address) Programmers don’t have to memorize name of operation to assign string value; assigning string value is just like assigning any other value