1 // Simplex.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 #include <fstream> 6 #include <iostream> 7

Size: px
Start display at page:

Download "1 // Simplex.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 #include <fstream> 6 #include <iostream> 7"

Transcription

1 1 // Simplex.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 #include <fstream> 6 #include <iostream> 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <math.h> 10 #include <conio.h> using namespace std; //global variables 15 int const max_parm=50,max_var=10,max_points=200; 16 int const max_vert=max_parm+1; 17 FILE *logfile; /*Function Declarations*/ 20 void calc_function(double ycalc[max_points], 21 double beta[max_parm], 22 double x[max_var][max_points],int npoint); int _tmain(int argc, _TCHAR* argv[]) 25 { 26 int const max_iter=2000; 27 double const tol=1e-6; 28 int nparm,nvar,npoint,nvert,ivert,ipoint,ivar,iparm,iter=0; 29 int iworst,ibest, nreplace, convg=0; 30 double beta[max_vert+2][max_parm], delta[max_parm],y[max_points]; 31 double x[max_var][max_points],res[max_vert+2],centroid[max_parm]; 32 double ycalc[max_points],z,rsquared,resprev; char asc[255]; 35 FILE *ascfile; printf("\tsimplex Nonlinear Least Squares Fit\n"); 38 printf("written by C. D. Keefe\nVersion 03/04\n"); 39 printf("this program will read a data file "); 40 printf("and calculate the least-squares fit.\n"); cout<<"data file? ";cin>>asc; 43 ascfile=fopen(asc,"r"); if(ascfile==null) 46 { 47 printf("\n%s does not exist.\n", asc); 48 goto exit_error; 49 } 50

2 51 //read number of independent points, variables, parameters 52 fscanf(ascfile,"%d",&npoint); 53 fscanf(ascfile,"%d",&nvar); 54 fscanf(ascfile,"%d",&nparm); //check and see if any of these exceed the maximum 57 if(npoint>max_points) 58 { 59 printf("\ntoo many points. Maximum is %d", max_points); 60 goto exit_error; 61 } if(nparm>max_parm) 64 { 65 printf("\ntoo many parameters. Maximum is %d", max_parm); 66 goto exit_error; 67 } 68 nvert=nparm+1; if(nvar>max_var) 71 { 72 printf("\ntoo many variables. Maximum is %d", max_var); 73 goto exit_error; 74 } //read initial value of parameters 77 for(iparm=0;iparm<nparm;iparm++)fscanf(ascfile,"%lg",beta[0]+iparm); //calculate incerements to parameters 80 for(iparm=0;iparm<nparm;iparm++) 81 { 82 delta[iparm]=.01*beta[0][iparm]; 83 if(delta[iparm]==0)delta[iparm]=0.01; 84 } //calculate initial set of vertices 87 for(ivert=1;ivert<nvert;ivert++) 88 { 89 //delta[ivert-1]*=2; //change one deltas each iteration 90 for(iparm=0;iparm<nparm;iparm++) 91 { 92 if(iparm==(ivert-1))beta[ivert][iparm]=beta[0][iparm]+2*delta[iparm]; 93 else beta[ivert][iparm]=beta[0][iparm]+delta[iparm]; 94 } 95 } //read input data as (x1,x2,...,y) then initial guesses or parameters 98 for(ipoint=0;ipoint<npoint;ipoint++) 99 { 100 for(ivar=0;ivar<nvar;ivar++)fscanf(ascfile,"%lg",x[ivar]+ipoint);

3 101 fscanf(ascfile,"%lg",y+ipoint); 102 } 103 fclose(ascfile); 104 //Open Log File, Overwrite if Already Exists. 105 logfile=fopen("simplex.out","w"); 106 setvbuf(logfile,null,_ionbf,0); //unbufffered output 107 fprintf(logfile,"\t\t\tlogfile FOR Nonlinear Least Squares Fit\n\n"); //calculate values of function with ititial parameter sets 110 for(ivert=nvert-1;ivert>=0;ivert--) 111 { 112 calc_function(ycalc,beta[ivert],x,npoint); 113 Z=0; 114 for(ipoint=0;ipoint<npoint;ipoint++) 115 Z+=(y[ipoint]-ycalc[ipoint])*(y[ipoint]-ycalc[ipoint]); 116 Res[ivert]=Z; 117 } 118 //find best set of parameters 119 ibest=0; 120 for(ivert=0;ivert<nvert;ivert++)if(res[ivert]<res[ibest])ibest=ivert; 121 resprev=res[ibest]; do { 125 iter++; //check if max ietartions exceeded if(iter>max_iter) 130 { 131 printf("\nmaximum iteration exceeded."); 132 fprintf(logfile,"\nmaximum iteration exceeded."); 133 goto exit_error; 134 } //find best and worst set of parameters 138 iworst=ibest=0; 139 for(ivert=0;ivert<nvert;ivert++) 140 { 141 if(res[ivert]<res[ibest])ibest=ivert; 142 if(res[ivert]>res[iworst])iworst=ivert; 143 } //output parameters for current iteration 146 printf("\niteration %d: Response %lg",iter,res[ibest]); 147 fprintf(logfile,"\niteration %d: Response %lg",iter,res[ibest]); 148 fprintf(logfile,"\nbeta\t\tresponse\n"); 149 for(ivert=0;ivert<nvert;ivert++) 150 {

4 151 for(iparm=0;iparm<nparm;iparm++) 152 fprintf(logfile,"%8.6lf\t", beta[ivert][iparm]); 153 fprintf(logfile,"%8.6lf",res[ivert]); 154 if(ivert==ibest)fprintf(logfile,"\tbest"); 155 if(ivert==iworst)fprintf(logfile,"\tworst"); 156 fprintf(logfile,"\n"); 157 } //calculate centroid 160 for(iparm=0;iparm<nparm;iparm++) 161 { 162 centroid[iparm]=0; 163 for(ivert=0;ivert<nvert;ivert++) 164 if(ivert!=iworst)centroid[iparm]+=beta[ivert][iparm]; 165 centroid[iparm]/=nparm; 166 } //output centroid 169 for(iparm=0;iparm<nparm;iparm++) fprintf(logfile,"%8.6lf\t", centroid[iparm]); 170 fprintf(logfile,"\tcentroid\n"); //calculate 1st reflected point beta[nvert][iparm] 174 for(iparm=0;iparm<nparm;iparm++) 175 beta[nvert][iparm]=2*centroid[iparm]-beta[iworst][iparm]; //calculate respond for 1st reflected point 178 calc_function(ycalc,beta[nvert],x,npoint); 179 Z=0; 180 for(ipoint=0;ipoint<npoint;ipoint++) 181 Z+=(y[ipoint]-ycalc[ipoint])*(y[ipoint]-ycalc[ipoint]); 182 Res[nvert]=Z; //output 1st reflected point 185 for(iparm=0;iparm<nparm;iparm++) fprintf(logfile,"%8.6lf\t", beta[nvert][iparm]); 186 fprintf(logfile,"%8.6lf",res[nvert]); 187 fprintf(logfile,"\tfirst reflected point\n"); /*If response at 1st reflected point is less than response 191 at best point expand search*/ 192 if(res[nvert]<res[ibest]) //1st reflected point is best 193 { 194 //calculate 2nd reflected point beta[nvert+1][iparm] 195 for(iparm=0;iparm<nparm;iparm++) 196 beta[nvert+1][iparm]=3*centroid[iparm]-2*beta[iworst][iparm]; //calculate respond for 2nd reflected point 199 calc_function(ycalc,beta[nvert+1],x,npoint); 200 Z=0;

5 201 for(ipoint=0;ipoint<npoint;ipoint++) 202 Z+=(y[ipoint]-ycalc[ipoint])*(y[ipoint]-ycalc[ipoint]); 203 Res[nvert+1]=Z; //output 2nd reflected point 206 for(iparm=0;iparm<nparm;iparm++) fprintf(logfile,"%8.6lf\t", beta[nvert+1][iparm]); 207 fprintf(logfile,"%8.6lf",res[nvert+1]); 208 fprintf(logfile,"\tsecond reflected point\n"); /*if response at 2nd reflected point is less than 1st reflected point 211 replace worst point with 2nd reflected point otherwise 1st reflected 212 point replaces worst point */ nreplace=nvert; 215 if(res[nvert+1]<res[nvert])nreplace=nvert+1; 216 for(iparm=0;iparm<nparm;iparm++) 217 beta[iworst][iparm]=beta[nreplace][iparm]; 218 Res[iworst]=Res[nreplace]; 219 } 220 else if(res[nvert]<res[iworst]) //1st reflected not the worst 221 { 222 //replace worst point with 1st reflected point 223 nreplace=nvert; 224 for(iparm=0;iparm<nparm;iparm++) 225 beta[iworst][iparm]=beta[nreplace][iparm]; 226 Res[iworst]=Res[nreplace]; 227 } 228 else //1st reflected point is worst -- contract 229 { 230 //calculate contracted point beta[nvert+1][iparm] 231 for(iparm=0;iparm<nparm;iparm++) 232 beta[nvert+1][iparm]=0.5*(centroid[iparm]+beta[iworst][iparm]); //calculate respond for contracted point 235 calc_function(ycalc,beta[nvert+1],x,npoint); 236 Z=0; 237 for(ipoint=0;ipoint<npoint;ipoint++) 238 Z+=(y[ipoint]-ycalc[ipoint])*(y[ipoint]-ycalc[ipoint]); 239 //Res[nvert+1]=sqrt(Z/(npoint-1)); 240 Res[nvert+1]=Z; //output contracted point 243 for(iparm=0;iparm<nparm;iparm++) fprintf(logfile,"%8.6lf\t", beta[nvert+1][iparm]); 244 fprintf(logfile,"%8.6lf",res[nvert+1]); 245 fprintf(logfile,"\tcontracted point\n"); /*if response at contracted point is less than the worst 248 replace worst with contracted point */ 249 if(res[nvert+1]<res[iworst]) 250 {

6 251 nreplace=nvert+1; 252 //replace worst point 253 for(iparm=0;iparm<nparm;iparm++) 254 beta[iworst][iparm]=beta[nreplace][iparm]; 255 Res[iworst]=Res[nreplace]; 256 } 257 else //both 1st reflected point and contracted point are worse 258 { //than worst move all sets of parameters close to best 259 for (ivert=0;ivert<nvert;ivert++) 260 for (iparm=0;iparm<nparm;iparm++) 261 if(ivert!=ibest)beta[ivert][iparm]= *(beta[ivert][iparm]+beta[ibest][iparm]); 263 } 264 } if(fabs(resprev-res[ibest])<tol)convg++; 267 else convg=0; resprev=res[ibest]; 270 }while((res[ibest]>tol)&&(convg<10)); //calculate values of function with best parameters 273 calc_function(ycalc,beta[ibest],x,npoint); Z=0; 276 Rsquared=0; 277 for(ipoint=0;ipoint<npoint;ipoint++) 278 { 279 Z+=(y[ipoint]-ycalc[ipoint])*(y[ipoint]-ycalc[ipoint]); 280 Rsquared+=y[ipoint]; 281 } 282 Rsquared=-Rsquared*Rsquared/npoint; 283 for(ipoint=0;ipoint<npoint;ipoint++)rsquared+=y[ipoint]*y[ipoint]; 284 Rsquared=1-Z/Rsquared; //converged results 287 printf("\ninterations converged. R^2 %lg",rsquared); 288 fprintf(logfile,"\niterations converged. R^2 %lg",rsquared); //Print final Betas 291 fprintf(logfile, 292 "\n\nfinal Converged Parameters\nk\tbeta"); 293 for(iparm=0;iparm<nparm;iparm++) 294 fprintf(logfile,"\n%d\t%lg",iparm,beta[ibest][iparm]); //finish up 297 fclose(logfile); 298 printf("\npress any Key to Exit..."); 299 getch(); 300

7 301 return EXIT_SUCCESS; //error handling 304 exit_error: printf("\nerror during run, program aborted.\n"); 305 if(logfile!=null) 306 { 307 fprintf(logfile, "\nerror during run, program aborted.\n"); 308 fclose(logfile); 309 } 310 getch(); 311 return EXIT_FAILURE; 312 }

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

More information

Lecture (03) x86 programming 2

Lecture (03) x86 programming 2 Lecture (03) x86 programming 2 By: Dr. Ahmed ElShafee ١ TOC The 80x86 Registers The Flag Register 80x86 Modes of operation ٢ Types of instruction set Complex instruction set computer (CISC): Large instruction

More information

#include <stdio.h> #include <math.h> int shownum(int digits[], int digitcount);

#include <stdio.h> #include <math.h> int shownum(int digits[], int digitcount); Problem 1: Programming in C [20 Points] Write a C program that takes as input a positive integer number and converts it to base 4. Some examples of input and output of this program are as follow: Example

More information

Programming I Assignment 04. Branching I. # Student ID Student Name Grade (10) -

Programming I Assignment 04. Branching I. # Student ID Student Name Grade (10) - Programming I Assignment 04 Branching I # Student ID Student Name Grade (10) - Delivery Date 1. يتم تسليم التمرين محلوال في خالل أسبوعا من تاريخ التمرين و يتم حذف درجتين من التمرين عن كل أسبوع تأخير 2.

More information

Friend Functions, Inheritance

Friend Functions, Inheritance Friend Functions, Inheritance Friend Function Private data member of a class can not be accessed by an object of another class Similarly protected data member function of a class can not be accessed by

More information

Getting Started with OpenDSS

Getting Started with OpenDSS Getting Started with OpenDSS Start your search for OpenDSS files on EPRI s link page: http://smartgrid.epri.com/simulationtool.aspx Downloads The Installer for the latest official release may be found

More information

- It computes the Standard Deviation by calculating the difference of each channel (R,G,B and A) of a pixel.

- It computes the Standard Deviation by calculating the difference of each channel (R,G,B and A) of a pixel. Standard Deviation: It is common to find comparison of two bitmaps in Image Processing Development. Comparison of two bitmaps means how each pixel of image1 is different from corresponding pixel of image2

More information

Linked List using a Sentinel

Linked List using a Sentinel Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include

More information

Communication With the Outside World

Communication With the Outside World Communication With the Outside World Program Return Code Arguments From the Program Call Aborting Program Calling Other Programs Data Processing Course, I. Hrivnacova, IPN Orsay I. Hrivnacova @ Data Processing

More information

Chapter 1 - What s in a program?

Chapter 1 - What s in a program? Chapter 1 - What s in a program? I. Student Learning Outcomes (SLOs) a. You should be able to use Input-Process-Output charts to define basic processes in a programming module. b. You should be able to

More information

Hands-On Lab: HORM. Lab Manual Expediting Power Up with HORM

Hands-On Lab: HORM. Lab Manual Expediting Power Up with HORM Lab Manual Expediting Power Up with HORM Summary In this lab, you will learn how to build a XP embedded images capable of supporting HORM (Hibernate Once Resume Many). You will also learn how to utilize

More information

Direct Memory Access. Lecture 2 Pointer Revision Command Line Arguments. What happens when we use pointers. Same again with pictures

Direct Memory Access. Lecture 2 Pointer Revision Command Line Arguments. What happens when we use pointers. Same again with pictures Lecture 2 Pointer Revision Command Line Arguments Direct Memory Access C/C++ allows the programmer to obtain the value of the memory address where a variable lives. To do this we need to use a special

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio

First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio C & C++ LAB ASSIGNMENT #1 First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio Copyright 2013 Dan McElroy Paycheck-V1.0 The purpose of this lab assignment is to enter a C or C++ into Visual Studio

More information

ECE264 Spring 2013 Exam 1, February 14, 2013

ECE264 Spring 2013 Exam 1, February 14, 2013 ECE264 Spring 2013 Exam 1, February 14, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

ECE264 Fall 2013 Exam 1, September 24, 2013

ECE264 Fall 2013 Exam 1, September 24, 2013 ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

tablica: array: dane_liczbowe

tablica: array: dane_liczbowe ARRAYS IN C/C++ tablica: array: dane_liczbowe float dane_liczbowe[5]; dane_liczbowe[0]=12.5; dane_liczbowe[1]=-0.2; dane_liczbowe[2]= 8.0;... 12.5-0.2 8.0...... 0 1 2 3 4 indeksy/numery elementów positions

More information

Performing Background Digital Input Acquisition Using the External Interrupt on a KPCI-PIO24 and DriverLINX

Performing Background Digital Input Acquisition Using the External Interrupt on a KPCI-PIO24 and DriverLINX Page 1 of 8 Performing Background Digital Input Acquisition Using the External Interrupt on a KPCI-PIO24 and DriverLINX by Mike Bayda Keithley Instruments, Inc. Introduction Many applications require the

More information

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each). A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

Windows 8 The notes in subsequent pages refer to a download of C++ that fails in Windows 8. For Windows 8, the following links were used:- http://www.windows8downloads.com/win8-dev-c--wdoxnrth/ http://sourceforge.net/projects/orwelldevcpp/?source=dlp

More information

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39 Binary Search Tree 1.0 Generated by Doxygen 1.7.1 Mon Jun 6 2011 16:12:39 Contents 1 Binary Search Tree Program 1 1.1 Introduction.......................................... 1 2 Data Structure Index 3

More information

Lecture 5 Files and Streams

Lecture 5 Files and Streams Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,

More information

GCC : From 2.95 to 3.2

GCC : From 2.95 to 3.2 GCC : From 2.95 to 3.2 Topics Simple changes name of standard include files, std::endl, iostream, throw statements, vector iterators More complicated changes string streams, parameterized macros, hash_map

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 10 October 1, 2018 CPSC 427, Lecture 10, October 1, 2018 1/20 Brackets Example (continued from lecture 8) Stack class Brackets class Main

More information

C programming for beginners

C programming for beginners C programming for beginners Lesson 2 December 10, 2008 (Medical Physics Group, UNED) C basics Lesson 2 1 / 11 Main task What are the values of c that hold bounded? x n+1 = x n2 + c (x ; c C) (Medical Physics

More information

C, C++, Fortran: Basics

C, C++, Fortran: Basics C, C++, Fortran: Basics Bruno Abreu Calfa Last Update: September 27, 2011 Table of Contents Outline Contents 1 Introduction and Requirements 1 2 Basic Programming Elements 2 3 Application: Numerical Linear

More information

NAG Library Function Document nag_prob_lin_non_central_chi_sq (g01jcc)

NAG Library Function Document nag_prob_lin_non_central_chi_sq (g01jcc) 1 Purpose NAG Library Function Document nag_prob_lin_non_central_chi_sq () nag_prob_lin_non_central_chi_sq () returns the lower tail probability of a distribution of a positive linear combination of 2

More information

Operating Systems Lab

Operating Systems Lab Operating Systems Lab Islamic University Gaza Engineering Faculty Department of Computer Engineering Fall 2012 ECOM 4010: Operating Systems Lab Eng: Ahmed M. Ayash Lab # 3 Fork() in C and C++ programming

More information

NAG Library Function Document nag_zero_nonlin_eqns_deriv_1 (c05ubc)

NAG Library Function Document nag_zero_nonlin_eqns_deriv_1 (c05ubc) c05 Roots of One or More Transcendental Equations c05ubc 1 Purpose NAG Library Function Document nag_zero_nonlin_eqns_deriv_1 (c05ubc) nag_zero_nonlin_eqns_deriv_1 (c05ubc) finds a solution of a system

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility, there are four library routines known as memory management

More information

Strings and Stream I/O

Strings and Stream I/O Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 some useful problems 2 Function: power Power iteration Power recursive #include #include 3 using std::cout; using std::cin; using std::endl; // function prototype

More information

ECE264 Summer 2013 Exam 1, June 20, 2013

ECE264 Summer 2013 Exam 1, June 20, 2013 ECE26 Summer 2013 Exam 1, June 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it. I

More information

CMSC 202 Midterm Exam 1 Fall 2015

CMSC 202 Midterm Exam 1 Fall 2015 1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

Defensive Programming

Defensive Programming Steven Zeil July 22, 2013 Contents 1 Common Assumptions 2 2 Documenting Assumptions 2 3 Guarding Assumptions 5 3.1 Guarding Assumptions with Assertions............................... 8 1 Defensive Programming

More information

Lab 1: First Steps in C++ - Eclipse

Lab 1: First Steps in C++ - Eclipse Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function Grade: / 20 Lab Exam 1 D500 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return 0? Answer: Anything that is not a floating point number such as 4.567 or

More information

ECE264 Spring 2014 Exam 2, March 11, 2014

ECE264 Spring 2014 Exam 2, March 11, 2014 ECE264 Spring 2014 Exam 2, March 11, 2014 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

The Data may not be disclosed or distributed to third parties, in whole or in part, without the prior written consent of Motion Workshop.

The Data may not be disclosed or distributed to third parties, in whole or in part, without the prior written consent of Motion Workshop. C API Reference Motion Version 2.6 www.motionnode.com www.motionshadow.com Copyright c 2017 Motion Workshop. All rights reserved. The coded instructions, statements, computer programs, and/or related material

More information

Raspberry Pi Basics. CSInParallel Project

Raspberry Pi Basics. CSInParallel Project Raspberry Pi Basics CSInParallel Project Sep 11, 2016 CONTENTS 1 Getting started with the Raspberry Pi 1 2 A simple parallel program 3 3 Running Loops in parallel 7 4 When loops have dependencies 11 5

More information

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name:  ID: Page 1 of 10 Name: Email ID: You MUST write your name and e-mail ID on EACH page and bubble in your userid at the bottom of EACH page including this page and page 10. If you do not do this, you will receive

More information

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example

More information

Engineering program development 7. Edited by Péter Vass

Engineering program development 7. Edited by Péter Vass Engineering program development 7 Edited by Péter Vass Functions Function is a separate computational unit which has its own name (identifier). The objective of a function is solving a well-defined problem.

More information

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS; 2005 7 19 1 ( ) Labeling 2 C++ STL(Standard Template Library) g++ (GCC) 3.3.2 3 3.1 Labeling SrcT DstT SrcT: unsigned char, shoft DstT: short typedef 1. unsigned char, short typedef Labeling

More information

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

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013 ANSI C Data Analysis in Geophysics Demián D. Gómez November 2013 ANSI C Standards published by the American National Standards Institute (1983-1989). Initially developed by Dennis Ritchie between 1969

More information

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

To become familiar with array manipulation, searching, and sorting. ELECTRICAL AND COMPUTER ENGINEERING 06-88-211: COMPUTER AIDED ANALYSIS LABORATORY EXPERIMENT #2: INTRODUCTION TO ARRAYS SID: OBJECTIVE: SECTIONS: Total Mark (out of 20): To become familiar with array manipulation,

More information

CA341 - Comparative Programming Languages

CA341 - Comparative Programming Languages CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data

More information

COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008

COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 Lab topic: 1) Take Quiz 4 2) Discussion on Assignment 2 Discussion on Assignment 2. Your task is to

More information

Introduction. Program construction in C++ for Scientific Computing. School of Engineering Sciences. Introduction. Michael Hanke.

Introduction. Program construction in C++ for Scientific Computing. School of Engineering Sciences. Introduction. Michael Hanke. 1 (63) School of Engineering Sciences construction in C++ for Scientific Computing 2 (63) Outline 1 2 3 4 5 6 3 (63) Motivations From Mathematical Formulae to Scientific Software Computer simulation of

More information

Lab 6 Due Date: Wednesday, April 5, /usr/local/3302/include/direct linking loader.h Driver File:

Lab 6 Due Date: Wednesday, April 5, /usr/local/3302/include/direct linking loader.h Driver File: Source File: ~/3302/lab06.C Specification File: /usr/local/3302/include/direct linking loader.h Driver File: /usr/local/3302/src/lab06main.c Implementation Starter File: /usr/local/3302/src/lab06.c.start

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

Installing and Using Dev-C++

Installing and Using Dev-C++ Installing and Using Dev-C++ 1. Installing Dev-C++ Orwell Dev-C++ is a professional C++ IDE, but not as big and complex as Visual Studio. It runs only on Windows; both Windows 7 and Windows 8 are supported.

More information

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

Ch 4. Parameters and Function Overloading

Ch 4. Parameters and Function Overloading 2014-1 Ch 4. Parameters and Function Overloading March 19, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

Unified Modeling Language a case study

Unified Modeling Language a case study Unified Modeling Language a case study 1 an online phone book use case diagram encapsulating a file 2 Command Line Arguments arguments of main arrays of strings 3 Class Definition the filesphonebook.h

More information

Sorting. Sorting. 2501ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University.

Sorting. Sorting. 2501ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University. 2501ICT/7421ICTNathan School of Information and Communication Technology Griffith University Semester 1, 2012 Outline 1 Sort Algorithms Many Sort Algorithms Exist Simple, but inefficient Complex, but efficient

More information

C++ Namespaces, Exceptions

C++ Namespaces, Exceptions C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design http://www.cplusplus.com/doc/tutorial/namespaces/ http://www.cplusplus.com/doc/tutorial/exceptions/ http://www.cplusplus.com/doc/tutorial/typecasting/

More information

Chapter 14 - Advanced C Topics

Chapter 14 - Advanced C Topics Chapter 14 - Advanced C Topics Outline 14.1 Introduction 14.2 Redirecting Input/Output on UNIX and DOS Systems 14.3 Variable-Length Argument Lists 14.4 Using Command-Line Arguments 14.5 Notes on Compiling

More information

Pointers and scanf() Steven R. Bagley

Pointers and scanf() Steven R. Bagley Pointers and scanf() Steven R. Bagley Recap Programs are a series of statements Defined in functions Can call functions to alter program flow if statement can determine whether code gets run Loops can

More information

Introduction. Lecture 5 Files and Streams FILE * FILE *

Introduction. Lecture 5 Files and Streams FILE * FILE * Introduction Lecture Files and Streams C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file, and

More information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

Program threaded-fft-bakery.cc

Program threaded-fft-bakery.cc 1 // 2D FFT Using threads 2 // George F. Riley, Georgia Tech, Fall 2009 3 // This illustrates how a mutex would be implemented using Leslie Lamport s 4 // "Bakery Algorithm". This algorithm implements

More information

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction 18.272 Praktikum: 4 Telebot system environment Lecturers Manfred Grove Houxiang Zhang TAMS, Department t of Informatics, Germany @Tams group Institute TAMS s http://tams-www.informatik.uni-hamburg.de/hzhang

More information

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It

More information

CSCI565 Compiler Design

CSCI565 Compiler Design CSCI565 Compiler Design Spring 2011 Homework 4 Solution Due Date: April 6, 2011 in class Problem 1: Activation Records and Stack Layout [50 points] Consider the following C source program shown below.

More information

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Outline 13.1 Test-Driving the Salary Survey Application 13.2 Introducing Arrays 13.3 Declaring and Initializing Arrays 13.4 Constructing

More information

V1190A/V1190B V1290A/V1290N VX1190A/VX1190B VX1290A/VX1290N FIRMWARE UPGRADE

V1190A/V1190B V1290A/V1290N VX1190A/VX1190B VX1290A/VX1290N FIRMWARE UPGRADE V1190A/V1190B V1290A/V1290N VX1190A/VX1190B VX1290A/VX1290N FIRMWARE UPGRADE C.A.E.N. S.p.A. Head office and laboratories: Via Vetraia, 11 I 55049 VIAREGGIO (ITALY) Phone: +39-0584-388398 Fax: +39-0584-388959

More information

9. Arrays. Compound Data Types: type name [elements]; int billy [5];

9. Arrays. Compound Data Types: type name [elements]; int billy [5]; - 58 - Compound Data Types: 9. Arrays An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object

More information

Functions & Memory Maps Review C Programming Language

Functions & Memory Maps Review C Programming Language Functions & Memory Maps Review C Programming Language Data Abstractions CSCI-2320 Dr. Tom Hicks Computer Science Department Constants c 2 What Is A Constant? Constant a Value that cannot be altered by

More information

NYU SCPS X Section 1 Unix System Calls. Fall 2004 Handout 8. Source code on the Web at mm64/x /src/doubly2.

NYU SCPS X Section 1 Unix System Calls. Fall 2004 Handout 8. Source code on the Web at  mm64/x /src/doubly2. Fall 2004 Handout 8 Source code on the Web at http://i5.nyu.edu/ mm64/x52.9232/src/doubly2.c 1 /* 2 Let the user type in positive numbers, not necessarily unique. Store them in 3 ascending order in a dynamically

More information

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam Lecture given by: Paolo Bientinesi First exam, 10.02.2015 The following document is a transcript from memory created

More information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York CSc 10200 Introduc/on to Compu/ng Lecture 19 Edgardo Molina Fall 2011 City College of New York 18 Standard Device Files Logical file object: Stream that connects a file of logically related data to a program

More information

ECE 5273 FFT Handout. On page 4.9 of the notes, there is a factor of N

ECE 5273 FFT Handout. On page 4.9 of the notes, there is a factor of N Spring 2007 ECE 5273 FFT Handout Dr. Havlicek This handout contains a listing of a C program called DoFFT that makes a floating point image, computes the DFT of the image, and writes the real and imaginary

More information

From Pseudcode Algorithms directly to C++ programs

From Pseudcode Algorithms directly to C++ programs From Pseudcode Algorithms directly to C++ programs (Chapter 7) Part 1: Mapping Pseudo-code style to C++ style input, output, simple computation, lists, while loops, if statements a bit of grammar Part

More information

CSC 270 Survey of Programming Languages. What is a Pointer?

CSC 270 Survey of Programming Languages. What is a Pointer? CSC 270 Survey of Programming Languages C Lecture 6 Pointers and Dynamic Arrays What is a Pointer? A pointer is the address in memory of a variable. We call it a pointer because we envision the address

More information

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming What the heck is STL???? Another hard to understand and lazy to implement stuff? Standard Template Library The standard template

More information

C Programming Lecture V

C Programming Lecture V C Programming Lecture V Instructor Özgür ZEYDAN http://cevre.beun.edu.tr/ Modular Programming A function in C is a small sub-program that performs a particular task, and supports the concept of modular

More information

C Legacy Code Topics. Objectives. In this appendix you ll:

C Legacy Code Topics. Objectives. In this appendix you ll: cppfp2_appf_legacycode.fm Page 1 Monday, March 25, 2013 3:44 PM F C Legacy Code Topics Objectives In this appendix you ll: Redirect keyboard input to come from a file and redirect screen output to a file.

More information

CSE 12 Spring 2016 Week One, Lecture Two

CSE 12 Spring 2016 Week One, Lecture Two CSE 12 Spring 2016 Week One, Lecture Two Homework One and Two: hw2: Discuss in section today - Introduction to C - Review of basic programming principles - Building from fgetc and fputc - Input and output

More information

Manfred Grove Houxiang Zhang

Manfred Grove Houxiang Zhang Praktik kum: 4 Telebot system environment Lecturers Manfred Grove Houxiang Zhang TAMS, Department of Informatics, Germany @Tams group Institute TAMS s http://tams-www.informatik.uni-hamburg.de/hzhang 1

More information

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver) Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program

More information

Fundamentals of Computer Programming Using C

Fundamentals of Computer Programming Using C CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions

More information

ECE264 Spring 2013 Final Exam, April 30, 2013

ECE264 Spring 2013 Final Exam, April 30, 2013 ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing

More information

EMBEDDED SYSTEMS PROGRAMMING Language Basics

EMBEDDED SYSTEMS PROGRAMMING Language Basics EMBEDDED SYSTEMS PROGRAMMING 2014-15 Language Basics (PROGRAMMING) LANGUAGES "The tower of Babel" by Pieter Bruegel the Elder Kunsthistorisches Museum, Vienna ABOUT THE LANGUAGES C (1972) Designed to replace

More information

1st Midterm Exam: Solution COEN 243: Programming Methodology I

1st Midterm Exam: Solution COEN 243: Programming Methodology I 1st Midterm Exam: Solution COEN 243: Programming Methodology I Aishy Amer, Concordia University, Electrical and Computer Engineering February 10, 2005 Instructions: 1. Time Allowed is 1 Hour. Total Marks

More information

Utility Classes Are Killing Us

Utility Classes Are Killing Us @yegor256 1 /13 Utility Classes Are Killing Us Utility классы нас убивают Yegor Bugayenko @yegor256 2/13 @yegor256 3 /13 10 N = INT(RND(1) * 100) 20 T = T + 1 30 IF T > 5 THEN GOTO 120 40 PRINT "Guess

More information

using namespace std; double compute_angle ( int idx, int niter ); void draw_angle_tree (int niter, int nangle); class Angles {

using namespace std; double compute_angle ( int idx, int niter ); void draw_angle_tree (int niter, int nangle); class Angles { Angles.hpp # include # include # include # include # include # include # include using namespace std; Purpose: Class Angles Interface

More information

Understanding Pointers

Understanding Pointers Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

More information