introduction to csce 221 - lab - parasol laboratory - comp… · introduction to csce 221 - lab...
TRANSCRIPT
![Page 1: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/1.jpg)
INTRODUCTION TO CSCE 221 -LABBASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD
![Page 2: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/2.jpg)
COMPUTERS
• Basic architecture
• Memory stores the data
• CPU is the brain
• Fetches data to and from memory
• Interplay with IO
CPU
• ALU
• Registers
• Control
Logic
Input
Devices
Output
Devices
Memory
• Data
• Instructions
![Page 3: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/3.jpg)
COMPUTERS
• Important as a programmer to
understand how your program and
rest of computer interact!
Hardware
Operating System
Compiler
Program
User
You are here!
![Page 4: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/4.jpg)
MEMORY
Function Stack (Statically Allocated)
Heap (Dynamically Allocated)
![Page 5: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/5.jpg)
C++ REVIEW
• Data
• Type – defines possible actions (primitives, classes – user-defined, templates)
• Variable – instance in memory
• Declaration – Tell the compile variable, function, or type exists
• Definition – Initializing value of variable, full specification of type or function
• Example
• int i; //declaration
• Foo bar(10); //declaration + definition
![Page 6: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/6.jpg)
C++ REVIEW
• Operations
• Math operations (+, -, *, /, %)
• Comparison (==, !=, >, <, etc)
• Assignment (=)
• Access ([], (), *, ->)
• Boolean (&, ^, !, &&, ||, etc)
• etc
![Page 7: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/7.jpg)
C++ REVIEW
• Loops
• Basic for
• for(int i = 0; i < 10; ++i);
• for(iterator i = begin(); i != end(); ++i);
• Basic while
• while(!done) do_something();
• Basic do while
• do { something(); } while(!done);
![Page 8: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/8.jpg)
C++ REVIEW
• Functions
• Basic signature
return_type function_name(param1, param2, …, paramN);
• Example
• void foo(int, char);
• Foo bar(int i, char c);
![Page 9: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/9.jpg)
LINUX
• PuTTY is an application to establish SSH connections
• Development machine: linux.cse.tamu.edu
• Open a PuTTY session and log into linux
![Page 10: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/10.jpg)
BASIC UNIX COMMANDS
• cd: change directory
• mkdir: make directory
• ls: list items in a directory
• g++-4.7: invoke GNU’s C++ compiler
• vim / emacs / nano: text editing
![Page 11: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/11.jpg)
VIM
Quick start guide
Vim cheat sheet
Vim settings file – put in home directory labeled “.vimrc”
![Page 12: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/12.jpg)
HELPFUL TOOLS FOR LINUX
• gdb – debugging tool for linux
• valgrind – memory leak detector/memory profiler
• screen – helpful when working remotely in a terminal. Saves the terminal
session even if the network connection cuts out
• LaTex – tool for creating documents
• top – monitor the system processes
![Page 13: Introduction to CSCE 221 - Lab - Parasol Laboratory - Comp… · INTRODUCTION TO CSCE 221 - LAB BASIC OF COMPUTERS, C++, UNIX, AND HELLO WORLD. COMPUTERS •Basic architecture •Memory](https://reader030.vdocuments.site/reader030/viewer/2022041003/5ea4c23fe99573137c6d151f/html5/thumbnails/13.jpg)
EXERCISE – HELLO WORLD
• Make a directory called 𝑙𝑎𝑏1 in your home folder
• Type mkdir lab1
• Type cd lab1
• Create a file called ℎ𝑒𝑙𝑙𝑜. 𝑐𝑝𝑝 using vim
• Type vim hello.cpp
• Write hello world to the screen
• Type i to go to insert mode then type the program
• Type esc to go to command mode and :wq to save and quit vim
• Compile using g++-4.7 and run your application
• Type g++-4.7 hello.cpp –o hello to compile
• Type ./hello to run the program