Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS101 Fall 2001 Lecture 1 In order to write a program, you must first telnet to your pegasus account and login either from a Rutgers computer in a lab,

Similar presentations


Presentation on theme: "1 CS101 Fall 2001 Lecture 1 In order to write a program, you must first telnet to your pegasus account and login either from a Rutgers computer in a lab,"— Presentation transcript:

1 1 CS101 Fall 2001 Lecture 1 In order to write a program, you must first telnet to your pegasus account and login either from a Rutgers computer in a lab, or from your home computer. If you haven’t yet opened a pegasus account, you should either go to a Rutgers computer lab, telnet to pegasus and put makeacct for your login name or telnet from home and put makeacct for your login name. Then follow the directions. Next, use the editor emacs to create a file and write the first Hello World program below. At the pegasus prompt, type emacs 101p1.cc and hit enter emacs 101p1.cc The program to type is #include main( ) { cout << “Hello World!\n”; }

2 2 In order to save what you typed into this file and exit, hold the control key down and type xsxc Once you do this, you are back at the pegasus prompt. In order to compile the file 101p1.cc which you just wrote, type g++ 101p1.cc In order to run the program you have just compiled, type a.out This will cause Hello World! to be printed to the screen. The newline character \n will cause the pegasus prompt to appear on the line directly below Hello World! The next program you will write will create to integer variables, add them together, and print the sum to the screen. C++ must declare the type of its variables, which, among other things, can be int, double, float and char Here is the next program, which should be called 101p2.cc #include main( ){ int x=10,y=20; cout << “The sum of “ << x << “ and “ << y << “ is “ << x+y <<“.\n”; }

3 3 Next type control xsxc in order to save your work and exit the file. Then compile it as before by typing g++ 101p2.cc and running it by typing a.out If you want to be able to run the previous program you compiled and this new program, then instead of compiling it by typing g++ 101p2.cc, you should type g++ -o 101p2 101p2.cc If you choose to compile the second program thi way, then in order to run it do not type a.out because that would just run the Hello World! Program again. Instead type 101p2 and you should see on the screen The sum of 10 and 20 is 30. It is not a good idea to keep the executable files around very long after you’ve run them, because they take up too much space on your pegasus shell account. If you want to see how much space they take up compared to the source code programs 101p1.cc and 101p2.cc, type ls -l 101p2 and you should see -rwxr--r-- 1 dupre dmcsprof 695404 Sep 5 20:55 101p2

4 4 Or something similar, since you are not a dmcsprof and the date will be different too. Notice the number 695404. This is about.7 megabytes, so only 2 such executables would fit on a floppy! Now type ls -l 101p2.cc and you should see something like -rw-r--r-- 1 dupre dmcsprof 300 Sep 5 20:55 101p2.cc This file is called the source code and is a text file and is so small in comparison to the binary executable 101p2 that 101p2 is over 2000 times the size of 101p2.cc! This is wgy it is a good idea to remove all executables after you are finished running them, because your pegasus quota, which you can see by typing quota -v, will be soon overrun if you keep them. The unix command to remove a.out and 101p2 is rm a.out 101p2


Download ppt "1 CS101 Fall 2001 Lecture 1 In order to write a program, you must first telnet to your pegasus account and login either from a Rutgers computer in a lab,"

Similar presentations


Ads by Google