HOMEWORK SUBMIT system: C++ Homework SUBMISSION for C++ Assignments for Jacobson
The program file names will be:
dates.cpp All lower case letters for the file name rectangles.cpp All lower case letters for file name BMI.cpp BMI is an acronym, so all UPPER CASE letters B M I questions.txt This is optional, if you want to submit here instead of handing the answers in on Friday during class.
The files you will upload will be named: forLoop.cpp questions.cpp CaSe SenSiTiVe - 52 letters a != A, etc.
its/free-software-players-and-viewers and download and then install SSH Secure Shell.
Telnet PuTTY <------ Not user friendly at all SSH Secure Shell <------ Download and install this one SSH Secure Shell is the one used in class.
[jacobson@weblab ~]$ g++ loop1.cpp COMPILE loop1.cpp [jacobson@weblab ~]$ ./a.out RUN (EXECUTE) the program a.out Please enter a positive integer: 5 The sum 1, 2, ..., 5 is 15 ------------------------------- -------- Textbook Programming Challenges - page 294 of book and see Monday 01/25 handout. ------------------------------- -------- 1. Sum of Numbers See page 233 of textbook See page 239 of textbook Write a program that asks for a positive integer value. Use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 5, the program will find the sum of the 1, 2, 3, 4 and 5. Actors needed in this drama: I Input: n will be the positive integer value, such as 5 or 50. O Output: sum will be the answer obtained that is to be output. P Processing: i will be the variable that starts out at 1 and is incremented each time so it ranges through the numbers 1, 2, 3, ..., n-1, n and at each value is added to the sum. I P O
[jacobson@weblab ~]$ g++ loop1.cpp [jacobson@weblab ~]$ ./a.out Please enter a positive integer: 5 The sum 1, 2, ..., 5 is 15 [jacobson@weblab ~]$ ./a.out Please enter a positive integer: 10 The sum 1, 2, ..., 10 is 55 [jacobson@weblab ~]$ ./a.out Please enter a positive integer: 100 The sum 1, 2, ..., 100 is 5050 [jacobson@weblab ~]$ ./a.out Please enter a positive integer: 4 The sum 1, 2, ..., 4 is 10
// Page 294 - Programming Challenges problem #1. #include <iostream> using namespace std; int main() { int i, n, sum; cout << "Please enter a positive integer: "; cin >> n; i = 1; sum = 0; while (i <= n) { sum = sum + i; i = i + 1; } cout << "\nThe sum 1, 2, ..., " << n << " is " << sum << endl << endl; }