1 C/C++ UM/MCSR. 2 Logging into the system using ssh Logging into the system from Windows: –Start the secure shell client: Start->Programs->SSH.

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

1 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d",
Introduction to Fortran and Fortran Compiling. Outline  Surfing websitewww.mcsr.olemiss.edu  Logging into the system via ssh 
Introduction to C Programming
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
CSCI 1411 FUNDAMENTALS OF COMPUTING LAB Lab Introduction 1 Shane Transue MSCS.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline History of C and C++ C++ Standard Library Object Technology Basics.
Introduction to C Programming CE Lecture 1 Introduction to C.
Three types of computer languages
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
C/C++ Compiling.
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
1 C/C++ Compiling. 2 Outline Surfing websitewww.mcsr.olemiss.edu Logging into the system via ssh Brief History of C/C++ languages.
1 C/C++ UM/MCSR Last modified: September 3, 2008.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Agenda What is Computer Programming? The Programming Process
COMPUTER SCIENCE I C++ INTRODUCTION
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Creating your first C++ program
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Chapter 02 (Part III) Introduction to C++ Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to Fortran Welcome to IT’s seminar on Fortran Sam Gordji, Weir 107.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
C Programming Lecture 3 : C Introduction 1 Lecture notes : courtesy of Woo Kyun and Chang Byung-Mo.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 5: Preparing C Programs
Introduction to C Topics Compilation Using the gcc Compiler
How to Program.
UMBC CMSC 104 – Section 01, Fall 2016
CS1010: Intro Workshop.
How to Start Programming in Linux Environment
Computer Science 210 Computer Organization
Chapter 2 - Introduction to C Programming
Computer Programming Techniques Semester 1, 1998
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Objectives Identify the built-in data types in C++
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
Computer Science 210 Computer Organization
Chapter 2 - Introduction to C Programming
1.13 The Key Software Trend: Object Technology
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Chapter 2 - Introduction to C Programming
Video Notes.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Presentation transcript:

1 C/C++ UM/MCSR

2 Logging into the system using ssh Logging into the system from Windows: –Start the secure shell client: Start->Programs->SSH Secure Shell->Secure Shell Client –Connect to willow: From the secure shell window, click Quick Connect. Then, from the Connect to Remote Host pop-up window, enter: Hostname: HostName User Name: UserName Click Connect. Logging into the system from Unix: –Start the Terminal: Finder  Utilities  Terminal –Type the following command: ssh Enter your password If you are a windows user and you want to download ssh: Go to MCSR Web at and click on the Software Tab, followed by the Secure Shell link. If you are a Unix, Linux, or MAC user, ssh will come with the operating system

3 A Brief History of C language In the early 1970s, Dennis Ritchie of Bell Laboratories was engaged in a project to develop new operating system. C programming language was then developed. In the early 1980's, also at Bell Laboratories, another C++ language was created. This new language was developed by Bjarne Stroustrup and was called C++ which was designed with OOP (Object Oriented Programming) features added to C without significantly changing the C component.

4 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230

5 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 Comments are set between /* and */

6 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 The C pre-processor replaces this directive with the contents of the stdio.h header file from the standard C library.

7 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 Every C program must have one main function.

8 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 Each variable must be explicitly defined as a specific type.

9 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 The stdio library defines the printf() function for creating output.

10 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 The stdio library defines the printf() function for creating output. \n is the newline character

11 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 The stdio library defines the scanf() function for capturing input.

12 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 %d tells scanf() to interpret the input as a decimal value

13 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 The = operator is used for assignment. The * operator is used for multiplication.

14 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d", &number); result = number *10; printf("The number multiplied by 10 equals %d\n", result); } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 %d tells printf() to treat the value of the result variable as a decimal nbr.

15 Simple C++ Program /* Take a number multiply it by 10 and display it */ #include int main() { int number, result; std::cout<<"Type in a number “<< std::endl; std::cin>>number; result = number *10; std::cout<<"The number multiplied by 10 equals “<<result; } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 C++ pre-processor directives include different versions of the standard library packages.

16 Simple C++ Program /* Take a number multiply it by 10 and display it */ #include int main() { int number, result; std::cout <<"Type in a number “<< std::endl; std::cin >>number; result = number *10; std::cout<<"The number multiplied by 10 equals “<<result; } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 std is an object which you can send messages to—messages such as: cout, cin, & endl.

17 Simple C++ Program /* Take a number multiply it by 10 and display it */ #include using namespace std; int main() { int number, result; cout <<"Type in a number “ << endl; cin>>number; result = number *10; cout<<"The number multiplied by 10 equals “ <<result; } Sample Program Output Type in a number 23 The number multiplied by 10 equals 230 You can use an object’s namespace, to keep from having to specify the name of the object each time you send it a message.

18 C/C++ source files suffixes.cpp,.cc,.c suffixes are used for C++ programs that are to be preprocessed, compiled and assembled.c for C programs that are to be processed, compiled and assembled.h or preprocessor (header) files

19 How to run compiled files The compiling commands create an executable file known as a.out unless specified otherwise. To execute your program, type./a.out and press Enter.

20 Compilation Details object.h object.cpp main.cpp object.s main.s object.o main.o Output Source codeAssemblyMachine Code

21 A detailed look into Compilers and Compiling commands C/C++ Compilers at UM/MCSR: –Intel C++ Compiler on redwood –Portland Group, GNU, and MPICH Compilers on Beowulf Cluster mimosa –GNU C Compiler and SUN STUDIO 8 C/C++ Compilers on willow

22 Loading the appropriate Intel Compiler Module Several versions/builds of Intel compilers are available on redwood. To compile, you must first pick which compiler version module you want to load, then load it. Before you can use the module command, you must source the correct setup file for your shell. –. /usr/share/modules/init/sh (if using ssh) (There should be a space between. and /usr) Then you use the module command: –module list (to see if any other versions of compiler modules are loaded) –module purge (to unload any other versions of compiler modules) –module list (to verify that other versions were successfully unloaded) –module avail (to see what versions of compiler modules are available to load) For example, to load the latest 10.1 version of the C Compilers: –module load c101 –module list These are the names of the modules and the compiler versions they correspond to: –intel-compilers for c 7.1 –intel-compilers for c 8.0 –intel-compilers for c 8.0 –intel-compilers for c 9.0 –intel-compilers for c 9.1 –intel-compilers.cc for c 10.1

23 Intel C++ Compiler on redwood Intel C/C++ Compilers(7.1, 8.0, 9.0, 9.1 & 10.0) –Before using the C/C++ Compiler on redwood, you must first load the appropriate Intel compiler module. –Then, to compile: icc example.c if using the 8.0 or later compiler ecc example.c if using the 7.1 compiler. With Intel compilers, the invocation syntax is the same regardless of whether your source file is C or C++.

24 Mimosa Mimosa: PGI CDK 7.2 Compilers –To compile with the C/C++ compilers, enter: /usr/local/apps/pgi-7.2/linux86/7.2/bin/pgCC example.c

25 GNU C Compiler and SUN STUDIO 8 C/C++ Compilers on willow gcc file1.c command is used to compile and link a C program on willow g++ file1.c command is used to compile and link a C++ program on willow

26 Willow & Common Compiler Flags Sun Studio C/C++ Compilers, Version 5.5: –To compile with C/C++, enter: cc example.c (C) CC example.c (C++) –Compilers located in /ptmp/studio8/SUNWspro/bin GNU C/C++ Compilers, Version – To compile with C/C++, enter: gcc example.c (C) g++ example.c (C++) –Compilers located in /usr/local/bin Use which to see which compiler version is being found. –which cc –which CC If there are no compilation errors this creates an executable file called a.out. To execute the C/C++ program, enter:./a.out.

27 Exercise 1: Compile C/C++ on willow 1.Log in to willow using the account: student 2.Change to your numbered working directory: –cd 1 3.Compile/execute hello.c using GNU C compiler –gcc hello.c –./a.out 4.Compile/execute simpleB.cpp using Sun’s C++ –CC simpleB.cpp –./a.out 5.Try to compile hello.c using Sun’s C compiler –cc hello.c

28 Example C/C++ Flags cc -c Compile or assemble the source files, but do not link. -S Stop after the stage of compilation proper -E Stop after the preprocessing stage -o newFilename Name executable something besides a.out -V Show the compiler version (SUN) -vShow the compiler version (GNU)

29 Exercise 2: Compiler Options 1.Compile/execute hello.c using GNU C compiler, and name the executable file helloc.exe –gcc hello.c –o helloc.exe –./helloc.exe 2.Determine what version of the GNU compilers are installed –gcc -v –g++ -v 3.Determine version of installed Sun’s compiler –CC –V –cc -V