Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS31 Discussion 1H Fall18: week 1

Similar presentations


Presentation on theme: "CS31 Discussion 1H Fall18: week 1"— Presentation transcript:

1 CS31 Discussion 1H Fall18: week 1
TA: Behnam Shahbazi Credit to former TAs: Chelsea Ju and Bo-Jhang Ho

2 Today’s Topic Project #1 IDE Setup and Configuration
Brief C++ Introduction Run Programs on Local & Seasnet We’ll do it together Compilation Errors vs Runtime Errors vs Wrong Answer

3 How am I? My name is Behnam
“Beh” means “best” in Persian and “nam” means “name”. 6th Year PhD student – Computer Science Dept. Research area: Text mining, NLP, Machine Learning Fan of playing sports like Soccer and Ping Pong

4 Resources My Office Hour & Location My Email
Wednesday 8:30am – 11:30am Boelter 3256S My Instructor’s & other TAs’ office hours

5 Grading Homework: 40% Midterm: 25% Final exam: 35% Assignments: 40%
7 projects The work should be submitted electronically Late submissions will be penalized by every second Midterm: 25%  Thursday, October 25 Thursday, November 15 Final exam: 35% Saturday, December 8 Assignments: 40%

6 Don’t give up!! Learning Tips Keep up with the lecture material
Start early Problem solving & coding may take longer than you think Read carefully Double/Triple check the project requirements Develop incrementally Add bits of code at a time, then compile, and run. It is easier to isolate any bugs, and to understand if the code is doing what you expected Don’t give up!!

7 Project #1 Due 11pm Monday October 8, 2018
Read the specification carefully, don’t get a 0 in any assignment! What to submit? C++ scripts original.cpp logic_error.cpp compile_error.cpp Report in MS Word format or Plain text report.doc or report.docx or report.txt Discuss any error messages the compiler reports, and incorrect/unusual results. Compress everything into one zip file, and submit online.

8 IDE Configuration IDE = Integrated Development Environment
A programming environment that has been packaged as an application program A graphical user interface (GUI), and a code editor A compiler A debugger A lot of different tools (energy analysis, CPU utilization, …) More on Class website Mac Linux Windows Xcode Command Line Terminal - Visual C++

9 Demo – Let’s rock! Demo Xcode Old-fashion way to write code
VIM to write code Use terminal to compile code and execute binary Useful commands to know: cd, ls, pwd, mkdir, “cd ..”, … Let’s run our code on Seasnet Connect to seasnet (example): Example: ssh ssh Copy your code on seasnet: scp PATH_TO_FILE/file.cpp

10 Example #1 – A simple program
Make groups of two people Please just copy and paste this to your code editor and run it #include <iostream> using namespace std; int main() { cout << "Hey, this really works!" << endl; return 0; }

11 Example #2 – A simple interactive program
Please just copy and paste this to your code editor #include <iostream> using namespace std; int main() { int num; cout << "Hey, give me a number: "; cin >> num; int numSquare = num * num; cout << "The square of this number is " << numSquare << endl; return 0; }

12 Details of build process
What exactly is going on when I click ? The hint from Xcode (the IDE)

13 Details of build process
What exactly is going on when I click ? The hint from Xcode (the IDE) Source code Executable or Binary Run the program

14 Details of build process
What exactly is going on when I click ? The hint from Xcode (the IDE) Compile (Build) Execute a program Source code Executable or Binary Run the program

15 Demo how to write a program using a terminal (Linux environment)
Demo time

16 Why do we need to compile a program?
Compile the source code by a compiler Source code (human readable) Executable/binary (machine readable)

17 What is C++? Is a (programming) language so that you can create a valid computer program C++ C++ C Assembly Machine code (Binary)

18 What is C++? Is a (programming) language so that you can create a valid computer program C++ C++ C Assembly Machine code (Binary)

19 What is C++? Is a (programming) language so that you can create a valid computer program C++ Object-oriented language C++ Procedural language C Assembly Machine code (Binary)

20 Let’s make some errors - 3 types of errors
Compilation error Syntax error Undeclared identifier Common function undeclared Program crashes (Segmentation fault) The program runs into an invalid state Incorrect memory access Runtime error Logic error Wrong answer

21 The skeleton C++ code This is the only time in this quarter I ask you to memorize codes!! #include <iostream> using namespace std; int main() { return 0; } Let’s go through some examples

22 Example #3 – Another interactive program
What is cin and cout? #include <iostream> using namespace std; int main() { int i, j; cout << "Please enter the value for i: " << endl; cin >> i; cout << "Please enter the value for j: " << endl; cin >> j; cout << "i + j = " << i + j << endl; return 0; }

23 Example #3 – Another interactive program (Cont’d)
Potential errors you can get: Unbalanced bracket Missing semicolon Undefined variable Undefined operator No number after return keyword Library doesn’t exist Etc.

24 Example #4 – Division Any errors we may get?
#include <iostream> using namespace std; int main() { int i, j; cout << "Please enter the value for i: " << endl; cin >> i; cout << "Please enter the value for j: " << endl; cin >> j; cout << "i / j = " << i / j << endl; return 0; } Any errors we may get?

25 Example #5 – What’s wrong with this code?
#include <iostream> using namespace std; int main() int a = 10; cout << A << endl; return 0; } Paste it to your programming editor to find the answers

26 Example #6 – Access invalid index in an array (advanced)
#include <iostream> using namespace std; int main() { int arr[100]; arr[ ] = 3; return 0; } Since there are only 100 available spots whose index ranged from 0 to 99, write back to any other index beyond this range will screw the memory and may crash the program

27 For project 1 – generate some bugs
You may want to explore the language a little bit… If Array For loop / while loop


Download ppt "CS31 Discussion 1H Fall18: week 1"

Similar presentations


Ads by Google