Sunteți pe pagina 1din 4

CS2400

Laboratory Assignment #3: More UNIX commands, math involving integers


and selection control structures
(100 pts)
First part of this lab assignment will give you more practice with some UNIX commands,
second part of this lab assignment will give you practice with integer division and the last
part will help you to understand selection control structures.

Step 1: Set up a separate directory for this lab.


First create a subdirectory called lab3.
a. Type
b. Type
c. Type

cd 2400/Labs
mkdir lab3
cd lab3

Step 2: Get familiar with ls, cd, cp, cat, mv and man UNIX commands
a. You already have used the ls command in the previous labs. To get more
details on this command type man ls at the system prompt. When you are done
with the reading enter q to quit.
b. Type

ls

/home/jsjsubm/cs2400

c. Type
ls -l /home/jsjsubm/cs2400
should see (among other things)
drwxr-xr-x

at the command line


at the command line. You

2 jsjsubm

faculty

512 Jan 18 20:13 dir6

-rw-r--r-1 jsjsubm
. . . . .

faculty

32 Jan 18 18:15 dir8

The first character on the line for dir6 indicates that dir6 is a directory and the first
character on the line dir8 (-) indicates that dir8 is a regular file. The next nine
characters represent three categories owner, group and world (you). Each
category represents r for read, w for write and x for execute permissions of a file.
For example, look at dir8, the owner has read and write privileges, but the group and
you have only read privileges.
d. Answer questions 1 4 on the answer sheet.

CS2400
Laboratory Assignment #3: More UNIX commands, math involving integers
and selection control structures
(100 pts)
e. You can display the contents of a file by typing the following command
cat /home/jsjsubm/cs2400/dir8
f.

Answer questions 5 and 6 on the answer sheet.

g. First type pwd to make sure that you are in lab3 directory.
h. To copy the files from dir1 to your directory type
cp /home/jsjsubm/cs2400/dir1/* .
(need the dot at the end this signifies the current directory as destination)
j.

Answer questions 7 and 8 on the answer sheet.

k.

Now type cd ../..


Type pwd

l. Answer question 9 on the answer sheet.


m. Just say you want to move yet_another_test in lab3 to lab2 (created last
week) directory.
First go to lab2 directory cd Labs/lab2
Type

mv ~/2400/Labs/lab3/yet_another_test .

(need the dot at the end this signifies the current directory as destination)
~ sign is the current users home directory.
n. Answer question 10 on the answer sheet.

CS2400
Laboratory Assignment #3: More UNIX commands, math involving integers
and selection control structures
(100 pts)

Step 3: Arithmetic Operations with Integers


Copy prog1.cc from the course account; be sure to get the lab3 version. Look at the
answer sheet for more details on step 3.

Step 4: (20 pts) Wage Plan


A bicycle salesperson is offered a choice of wage plan: (a) $5.50 per hour for 40 hours
plus a 10% commission on sales (b) a straight 15% commission on sales with no other
salary. Write a program that will take as input the sales persons expected weekly sales
and will output the expected wages paid under each plan as well as announcing the bestpaying plan. Implement this program (call it prog2.cc) using if-else statements
(pages 75 -76, 95 in your text).
Declare rate per hour (5.50), the two commissions (10% and 15%) as named
constants in your program (pages 95 - 96 in your text).
Do not forget to include the magic formula (pg 56) and format the output to two
decimal places.
A sample dialogue from this program:
./a.out
Enter the weekly sales amount > 4395.00
Amount
Plan 1
Plan 2
Plan 1

of sales $4395.00
pays $659.50
pays $659.25
is better

./a.out
Enter the weekly sales amount > 4500.00
Amount
Plan 1
Plan 2
Plan 2

of sales $4500.00
pays $670.00
pays $675.00
is better

Begin your program with the standard comment box. The program should be
thoroughly documented and follow the style guidelines discussed in class.
Also turn in a printout of your source code only with the cover sheet showing
name/date/time.
Be sure to electronically submit all code from this lab on Blackboard.
3

CS2400
Laboratory Assignment #3: More UNIX commands, math involving integers
and selection control structures
(100 pts)

Scoring for step 4


2 points

comments (name, date, etc and the introduction to the program)

2 points

named constants in uppercase.

2 points

meaningful variable names and document the variables

1 points

prompts to user.

8 points

correct calculations and if-else statement

1 point

style (indenting)

2 points

write out all items requested, labeling each item.

2 points

appearance of output (spacing, format to 2 decimal places)

S-ar putea să vă placă și