Similar documents
Program Organization and Comments

JAVA ~ as opposed to Java Script

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

AMCAT Automata Coding Sample Questions And Answers

Why VC++ instead of Dev C++?

COMP s1 Lecture 1

ECE15: Homework 10. void wordstats(file *fp, char string[]) { void printfrequencies(file *fp) {

Decision Making -Branching. Class Incharge: S. Sasirekha

CSE 374 Programming Concepts & Tools

1 SUNRISE-SUNSET SUNRISE/SUNSET LIBRARY 1

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Arrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga

The C standard library

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

IMSL C Numerical Library

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

Preview from Notesale.co.uk Page 6 of 52

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

BİL200 TUTORIAL-EXERCISES Objective:

Unix and C Program Development SEEM

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

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Overview (1A) Young Won Lim 9/14/17

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Programming and Data Structure

High Performance Computing

Should you know scanf and printf?

Overview (1A) Young Won Lim 9/9/17

C Program Development and Debugging under Unix SEEM 3460

CS16 Exam #1 7/17/ Minutes 100 Points total

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

Overview (1A) Young Won Lim 9/25/17

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

Technical Questions. Q 1) What are the key features in C programming language?

Creating, Compiling and Executing

CSE 351. GDB Introduction

Chapter 1 Getting Started Structured Programming 1

Problem Set 1: Unix Commands 1

just a ((somewhat) safer) dialect.

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

Introduction: The Unix shell and C programming

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Scientific Programming in C VI. Common errors

Dynamic Memory Allocation and Command-line Arguments

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

High Performance Computing MPI and C-Language Seminars 2009

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out

ANSI C Programming Simple Programs

Chapter 9 Lab Text Processing and Wrapper Classes

CSE 351. Introduction & Course Tools

Lab 5 Pointers and Arrays

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

Lecture (03) x86 programming 2

Kurt Schmidt. October 30, 2018

Lesson 7. Reading and Writing a.k.a. Input and Output

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Lecture 07 Debugging Programs with GDB

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

Array Initialization

Informática Ingeniería en Electrónica y Automática Industrial

Introduction to C An overview of the programming language C, syntax, data types and input/output

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

C programming basics T3-1 -

Getting Started with OpenDSS

CS3157: Advanced Programming. Outline

Object-Oriented Programming

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

Fundamentals of Programming Session 8

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

The Newton Method as a Short WEB Example

Introduction to Computing Lecture 01: Introduction to C

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

Code Created In Class To Help With Lab 6 October 8, 2018 CIS 1057 Fall 2018

Functions. Using Bloodshed Dev-C++ Heejin Park. Hanyang University

Project 1: How to Make One Dollar

C Program Structures

Fundamentals of Computer Programming Using C

C Language Coding Standard

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers

printf( Please enter another number: ); scanf( %d, &num2);

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

Code Blocks Cannot Find Compiler Executable Windows 7

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

VIRTUAL REALITY WORLD OF SUNDIALS ~ you can walk around them. Earlier Windows XP systems and current Vista win64 as well.

CS-201 Introduction to Programming with Java

The C Pre Processor ECE2893. Lecture 18. ECE2893 The C Pre Processor Spring / 10

Transcription:

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 Dev-Cpp 5.5.3 TDM-GCC x64 4.7.1 Setup.exe This installed and ran first time with no problems. Jan 14, 2014 Windows Vista and before There is one free C or C++ compiler available with which this program has been tested. http://www.bloodshed.net/devcpp.html http://www.bloodshed.net/dev/devcpp.html about the C products download options If you have no C nor C++ at all, then you should download the full system Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2 Dev-C++ version 4.9.9.2, includes full Mingw compiler system with GCC 3.4.2 and GDB 5.2.1 See NEWS.txt for changes in this release. NOTE: Windows 8 ~ this crashes as soon as you try to compile. See the notes above for Windows 8.

SOME NOTES ON PROGRAMMING IN "C" The program for horizontal dials is shown below. This is a conversational program and does not use graphics nor a GUI (graphic user interface). This does not use object oriented features, it is as simple as it can be. #include <stdio.h> #include <math.h> http://www.windows8downloads.com/win8-dev-c--wdoxnrth/ http://sourceforge.net/projects/orwelldevcpp/?source=dlp #define degtorad ((2 * 3.1416) / 360) #define radtodeg (360 / (2 * 3.1416)) int main () { int i, ii ; float j; float lat; float sinlat; float hlat ; float lng; float ref; float corh; float hla; // main procedure // working integers // working float // latitude and // and sin of latitude // hour line angle // longitude // reference meridian // correction for longitude // hour line angle printf ("*------------ Horizontal Dial ------------*\n"); printf ("www.illustratingshadows.com cpp-hdial.cpp\n"); printf ("*----------- March 7, 2007 0838 ----------*\n"); printf ("Enter latitude "); scanf ("%f", &lat) ; printf ("Enter longitude "); scanf ("%f", &lng); printf ("Enter legal meridian "); scanf ("%f", &ref); printf ("Design latitude: printf ("Design longitude: printf ("Reference meridian: %7.2f \n", lat); %7.2f \n", lng); %7.2f \n", ref); corh = (4*(lng-ref)) / 60 ; printf ("Correction to shadow %7.2f hours \n", corh); printf ("Correction to shadow %7.2f minutes \n", corh*60); printf ("\n"); printf ("Corrected hour line angles \n" ) ; printf ("morning hours first\n");

for (i = -6 ; i <7 ; i++ ) { if (i==0) {printf ("\nnoon\n"); if (i==1) {printf ("noon\n\n"); sinlat = sin( degtorad*lat ) ; // get the hour angle of the sun ii = (-1)*i ; j = 15 * (ii+corh) ; /* get the resulting hour line angle ~ atan(sin(lat)*tan(hr*15) */ hlat = sinlat * tan(degtorad*j) ; /* get the hour line angle back to degrees */ hla = radtodeg*( atan(hlat) ) ; } printf ("Hour: %3i hour angle: %6.2f Angle: %6.2f \n", i, j, hla ); printf ( "afternoon hours last\n" ); printf ( " \n"); printf ( "*** END *** (enter any letter and return to quit)\n") ; } scanf ("%f", &ref); return 0; // a pause using any old variable "C" was the original language in the "C" series of languages. It was structured, in that the IF THEN program flow was strongly supported, and the GOTO was diminished. As programming moved from sequential code towards event driven code, the concept of "objects" as opposed to simple variables or structures of variables came into play. And further, the concept came into existence of building code into the object to handle standard work that these objects might need done for them. These code segments, directly tied to the objects, were known as methods. This concept was used for many years in the IBM mainframe world where interrupt driven code was not new. However, as the UNIX world moved into more mainstream activity, the UNIX community considered these to be new concepts. Be that as it may, the development of objects and their methods was formalized as a concept in the development of C++, a language derivative of "C". The object and its methods were abstracted further into classes. A class was a definition of an object, or rather what it would be like. Thus a class was more of a dictionary, and the objects themselves were constructed from that dictionary. This was seen in the DeltaCAD definition of a human interaction window, and its subsequent generation or construction, and its subsequent use. However, in a true object oriented system, the methods became inter-related. That interaction allowed simple events to cause the updating of many objects. One example is the Windows display of a folder of files, and how that display is updated automatically when in another window a file is added or dropped from that folder. NOTE: January 2008: Microsoft provides a free Visual C++ Express system available at:- http://msdn.microsoft.com/vstudio/express/downloads/default.aspx These programs can be pasted directly into them if you use their Win32 Console selection, and they run. However, whereas these free systems from BLOODSHED are simple and unsophisticated, they produce executable files easily sent to others. Whereas the Visual C++ Express system is glossy and up to date, sending applications is nowhere near as simple. As an overview, this is shown on the next few pages.

SOME NOTES ON PROGRAMMING IN C++ Always check the current program for the latest, with corrections. ////////////////////////////////////////////////////////////////////////////////////////// // h or v Dial but using object oriented methods TO SOME EXTENT // // mostly to show class, method, and function constructs // // // // www.illustratingshadows.com Simon Wheaton-Smith FRI, MBCS, CITP Jan 15, 2014 // ////////////////////////////////////////////////////////////////////////////////////////// /* * latest version tested in Windows 8 January 15, 2014 * http://www.windows8downloads.com/win8-dev-c--wdoxnrth/ * http://sourceforge.net/projects/orwelldevcpp/?source=dlp * Dev-Cpp 5.5.3 TDM-GCC x64 4.7.1 Setup.exe */ #include <stdio.h> #include <math.h> #include <string.h> #define radians (2*3.14159/360) #define degrees (360/(2*3.14159)) class sundial { // the dial itself float lat ; float lng ; float ref ; char * dtype; // an hour line float hr ; float hla ; // methods public: // set and fetch the dial type void settype (char * dialtype){ this->dtype = dialtype; // printf ("type was: "); printf (this->dtype); printf ("\n"); char * gettype (){ return this->dtype; // set dial location void setlat (float latparm){ this->lat = latparm; this->hr = 12.001; this->hla = 0.001; void setlng (float lngparm){ this->lng = lngparm; void setref (float refparm){ this->ref = refparm; // set a time and get an hour line angle void sethr (float hrparm){ this->hr = hrparm; float gethla () { float wkhr; /* * am pm am pm * test data for h dial 33.5/112.1/105: 9.00 3.00-35.34 23.25 * test data for v dial 33.5/112.1/105: 9.00 3.00-46.97 32.99 */ if (0==strncmp(this->dType,"h",1)){ wkhr = this->hr + ((this->ref - this->lng)*4/60); hla = degrees* atan( sin(radians*this->lat) * tan(radians*wkhr*15) ); return this->hla; if (0==strncmp(this->dType,"v",1)){ wkhr = this->hr + ((this->ref - this->lng)*4/60); hla = degrees* atan( cos(radians*this->lat) * tan(radians*wkhr*15) );

return this->hla; // end of class int main () { // variables for the main program float lat, lng, ref; float f; float hla; char dtype[5]; char * testtext; // create an instance of the sundial printf ("*** GENERIC SUNDIAL GENERATOR ***\n"); sundial mysundial; // ask for the kind of dial ~ affects the formula to use printf ("Enter h or v for dial type (lower case): "); scanf ("%s", &dtype) ; mysundial.settype(dtype); /* code determines dial type and confirms in plain language */ testtext = mysundial.gettype(); if (0==strncmp(testtext,"h",1)) { printf ("HORIZONTAL DIAL [%s]: \n",testtext ); if (0==strncmp(testtext,"v",1)) { printf ("VERTICAL DIAL [%s]: \n",testtext ); printf ("Enter latitude "); scanf ("%f", &lat) ; mysundial.setlat (lat); // printf ("LATITUDE ENTERED WAS: %6.3f \n",lat); printf ("Enter longitude "); scanf ("%f", &lng) ; mysundial.setlng (lng); // printf ("LONGITUDE ENTERED WAS: %6.3f \n",lng); printf ("Enter reference meridian "); scanf ("%f", &ref) ; mysundial.setref (ref); // printf ("L.MERIDIAN ENTERED WAS: %6.3f \n",lng); // get an hour line angle for this hour ~ -3 is 9am, 0 is noon, 3 is 3pm for (f = -5 ; f < 6 ; f++ ) { mysundial.sethr (f); hla = mysundial.gethla(); if ( f == 0) { printf("\n");} printf ("HOUR: %2.1f Hour Line Angle: %6.3f \n", f+12, hla ); if ( f == 0) { printf("\n");}

PROGRAMMING IN VISUAL C++ EXPRESS (Microsoft) Visual C++ Express is downloaded, first as a small installer, then as several very large files of stuff, which it then installs if the installer likes your system. This is from Microsoft, and the registration process worked easily. The url for the Visual Basic Express, and other light weight Express products is:- http://msdn.microsoft.com/vstudio/express/downloads/default.aspx And click on the Visual C++ 2008 (or whatever) DOWNLOAD panel, and proceed. Again, this is a free product. Remember, that while this is a free system, and while it is a lot more up to date than the other C compilers discussed by Illustrating Shadows, this Microsoft free product is not without its disadvantages. This Microsoft Visual C++ system, while free, does not allow for simple transmission of finished applications to others. Whereas the free C systems discussed elsewhere on the Illustrating Shadows web site and CD, while having less features, does allow for much less complicated transmission of completed applications. WINDOWS CONSOLE PROGRAM (The simplest) The simplest programming is for a console program, such as run in a "DOS" window, one follows the same process, but instead of selecting Win32 Project, select Win32 Console Application, entering a name. The next screen allows you to select Application Settings, and, as below, you select Console Application. Then FINISH builds the project and generates sample code.

For the console program, running in a DOS window, the non windows C code may be pasted into the int _tmain section, the old main function being deleted, the #include and #define statements moved up to the template's #include, and the program tested with DEBUG, and that in turn triggers a build process, and upon completion, the program is run in a DOS window.

The source code would look like:- // hdialvcw32console.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <math.h> #define degtorad ((2 * 3.1416) / 360) #define radtodeg (360 / (2 * 3.1416)) int _tmain(int argc, _TCHAR* argv[]) { int i, ii ; float j; // working integers // working float float lat; // latitude and lat = 32.75 ; // no good reason for this float sinlat; // and sin of latitude float hlat ; // hour line angle float lng; // longitude lng = 108.2 ; // no good reason for this float ref; // reference meridian ref = 105 ; // no good reason for this float corh; // correction for longitude float hla; // hour line angle printf ("*------------ Horizontal Dial ------------*\n"); printf ("www.illustratingshadows.com cpp-hdial.cpp\n"); printf ("*----------- March 7, 2007 0838 ----------*\n"); printf ("Enter latitude "); scanf ("%f", &lat) ; printf ("Enter longitude "); scanf ("%f", &lng); printf ("Enter legal meridian "); scanf ("%f", &ref); printf ("Design latitude: printf ("Design longitude: printf ("Reference meridian: %7.2f \n", lat); %7.2f \n", lng); %7.2f \n", ref); corh = (4*(lng-ref)) / 60 ; printf ("Correction to shadow %7.2f hours \n", corh); printf ("Correction to shadow %7.2f minutes \n", corh*60); printf ("\n"); printf ("Corrected hour line angles \n" ) ; printf ("morning hours first\n"); for (i = -6 ; i <7 ; i++ ) { /* T E S T V A L U E S *------------ Horizontal Dial ------------* www.illustratingshadows.com cpp-hdial.cpp *----------- March 7, 2007 0838 ----------* Enter latitude 32.75

Enter longitude 108.2 Enter legal meridian 105 Design latitude: 32.75 Design longitude: 108.20 Reference meridian: 105.00 Correction to shadow 0.21 hours Correction to shadow 12.80 minutes Corrected hour line angles morning hours first Hour: -6 hour angle: 93.20 Angle: -84.10 Hour: -5 hour angle: 78.20 Angle: 68.88 Hour: -4 hour angle: 63.20 Angle: 46.96 Hour: -3 hour angle: 48.20 Angle: 31.18 Hour: -2 hour angle: 33.20 Angle: 19.49 Hour: -1 hour angle: 18.20 Angle: 10.09 noon Hour: 0 hour angle: 3.20 Angle: 1.73 noon Hour: 1 hour angle: -11.80 Angle: -6.45 Hour: 2 hour angle: -26.80 Angle: -15.28 Hour: 3 hour angle: -41.80 Angle: -25.81 Hour: 4 hour angle: -56.80 Angle: -39.58 Hour: 5 hour angle: -71.80 Angle: -58.71 Hour: 6 hour angle: -86.80 Angle: -84.10 afternoon hours last *** END *** (enter any letter and return to quit) */ if (i==0) {printf ("\nnoon\n"); if (i==1) {printf ("noon\n\n"); sinlat = sin( degtorad*lat ) ; // get the hour angle of the sun ii = (-1)*i ; j = 15 * (ii+corh) ; /* get the resulting hour line angle ~ atan(sin(lat)*tan(hr*15) */ hlat = sinlat * tan(degtorad*j) ; /* get the hour line angle back to degrees */ hla = radtodeg*( atan(hlat) ) ; j, hla ); } printf ("Hour: %3i hour angle: %6.2f Angle: %6.2f \n", i, printf ( "afternoon hours last\n" ); printf ( " \n"); printf ( "*** END *** (enter any letter and return to quit)\n") ; } scanf ("%f", &ref); return 0; // a pause using any old variable