What on Earth is a "FAQ" anyway?
FAQ stands for Frequently Asked Questions. It is here that you will find answers to questions asked via e-mail. Before e-mailing a question to the TA and proctors, you should check here to see if it has already been asked.
This FAQ will be updated approximately once a week.
How do I compile our assignments at home on our PCs then transfer it over?
In order to compile programs on your computer at home, you need to have a C++ compiler installed on your PC. If you have one, then the instructions that come with the compiler will tell you how to compile.
After you have the program working on your PC, you can then transfer the source file from your PC to your Unix account. There are several ways to do this.
One way is to save it onto a floppy disk and take it to the basement of AP&M where one of the "zebras" can show you how to ftp (or put it using fetch, if your computer is a Macintosh) it to your Unix account. Someone just told me that ftp is available on Windows 95. If this is true, then you might be able to do this from home.
Since you said that you have Eudora on your PC, you should be able to just send the source file as a message or an attachment. Refer to the Eudora instructions for details. After this is done, you can save the message or attachment from the mail program on your Unix account. If you are saving it as a message, do not forget to remove the mail header info.
There are two possible ways you can transfer a file using a terminal program. One way is to use a file transfer protocol. Kermit is the only one I noticed that is available on the class accounts, there might be others. You need to look at the documentation for the terminal program on your PC and the man or help pages for kermit on your Unix account. Again, the zebras should be able to help you sort through this info.
Also, many terminal programs allow you to insert a text (or ASCII) file instead of typing. If this is the case, you can open vi and set it in the insert mode, then insert the text file using the command on your terminal program. You can then press 'esc' and write it to a file as if you typed it in manually.
No matter which method you try, there are a couple of important points to remember:
If you don't have a compiler and have a PC, modem, terminal program, and dialin account, you can work on your class account from home. After dialing in and entering your dialin user name and password, you can telnet to your class account. Be aware that if you have time restrictions on your dialin, they will also apply in this case. Similarly, if you have access to another Unix account, you probably can telnet into and use your class account from that account. There are man and help pages available for telnet.
Your best sources of information are the documentation, the zebras, Network Operations, and the TA/Proctors.
The program that you turned in Monday was just practice. Go ahead and turnin assignment #1 whenever you want. We will collect #1 on the 18th, so don't turnin #2 until after that.
When we turn in the executable, does the file need to be named a.out?
When you use the turnin program, you should turnin your .C file only, not the executable. When we grade your program, we will compile the source code that you have written. The name does not matter, when it is turned in it is given your login name.
An unsigned long integer can only contain values from 0 to 2^32 - 1. When a number outside of this range, such as your 9876598765, is entered it is interpreted in the valid range. This is known as integral wrapping. For example, the value 2^32, when entered, is actually interpreted by the computer as 0. This is why gigantic numbers are often misinterpreted as relatively small ones.
The program p0.C created during the lab orientation tour is just an example that will not count for any grade.
The program p1.C, in your handout "Programming Assignments" that is due this Saturday, 1/18 at 9am is important. You may "vi p1.C" again and insert that header line to identify the owner.
Then use the turnin program as many times as you want until the deadline date: turnin -c cs9w p1.C.
When I compile, I get a bad magic number error, what's wrong?
This message comes up when you name your file with a little c (pa.c) instead of a big C (pa.C). The little c means a C program, and the big C means a C++ program.
Would any entered number with an embedded zero in it choke the loop? No, an embedded zero in the input will work ok. Here is the run of the program with an input of "103" (embedded zero). This program code is written using the method as we discussed in class. To test out this same object code, copy the object code into your home directory and test it out with input so that your program will do the same.
cp ~/../public/assignments/p2 . (Note: The period is required)
Output:
Enter a whole number to be printed in reverse: 103
The number 103 in reverse is: 301 using the while loop
The number 103 in reverse is: 301 using the for loop
The number 103 in reverse is: 301 using the do loop
Is it just an entry of zero by itself that messes up the for and while loop?
From the motd (message of the day) on sdcc8:
1/16 PA#2 Input will *NOT* contain leading zeros (e.g. 008 08 0 )
Therefore no value of just ZERO will be entered. Please remember *NOT* to use any constructs that have not been introduced yet. So for PA #2 (Loops), the if statement was not yet introduced.
Do NOT worry about any input of ZERO from the grading program.
Will we continue to get the homeworks assigned early (like p2 and p3)?
Yes, you will get these in advance. I (S. Marx) am programming the assignments first and testing them out BEFORE you get an impossible assignment.
Is early turn in time Tuesdays by 3 pm (not 9am)?
Yes, starting with PA #3 on Tuesday 3pm 1/28.
Please explain the three components of a for loop.
Not counting the loop body, the three components of a for(<Initialization>; <Test>; <Update>) are:
NAME IN EXAMPLE BELOW
1. Initialization i = 0
2. Test i < 5
3. Update i++
The loop executes as follows:
Initialization Test (TRUE) Loop Body Update Test (TRUE) Loop Body Update ... Test (FALSE) (Loop exits)
For example,
for (i = 0; i < 5; i++)
{
cout << i << endl;
}
Will output:
0 1 2 3 4
An important thing is to make sure that the loop ultimately exits, otherwise it will be an infinite loop.
For example:
case 1:
case 2:
case 3:
...
case 100:
Yes you do understand the switch statement syntax and you certainly could program the switch with 100 case statements. This is a brute force method (just making it work and not thinking about a step by step method of solving the problem). Putting 100 case statements is like adding numbers with your finger and toes. There has got to be a better way.
I suggest you look at the problem in 2 steps. The first step is to determine the letter grade. The second step is to determine the symbol (++ + -) that is appended. So you start looking at patterns.
Well the A is: 100
99
98
97
...
90
the B is: 89
88
87
...
80
the C is: 79
78
77
...
70
What really makes that A an A, a B a B and ...? If you look at the first digit, there is a pattern. That is how you can determine the letter grade. We actually used this algorithm in reversing the number in PA#2. Now this is easy to implement using if else and switch statements.
The second step is to determine the symbol (++ + -) that is for A, B, and C only. So:
100 A++ 99, 98, 97 A+ 89, 88, 87 B+ 79, 78, 77 C+ .... A-
Now you might see another pattern. (Hint: it's not the 1st digit). This is a pretty good start in attacking the problem.
How do I limit the use of the "+" and "-" grades to the letter grades A, B, and C (70-99)?
You have to think again of what makes an A, a B, and a C? Yes, it's the first digit again. Take that first digit and limit this range by using if else or switch statements, then you look at the 2nd digit that determines the + or -.