CS201 First Homework Lol
CS201 First Homework Lol
CS201 First Homework Lol
CHANGEME: 00
Stefano Fochesatto
September 1, 2019
1 Design
The first program is a very simple ”Hello World” program with
a little bit of a twist. First it simply prints out a string that says
”Hello World”, then we were asked to print ”Hello World” 10 times
to demonstrate loops. So to do so I demonstrated printing out
multiple strings using a for loop, while loop, do while loop, and a
nested four loop. The next program prints out the epic Beowulf
from from a .txt file, doing so line by line to retain formatting.
The Last program prints out a description of the game Nim, I
started writing the game but it’s not done yet.
2 Post Mortem
With the Poem program I could only open the .txt file using an
explicit directory, even with the Beowulf.txt file in the project
directory the command ”Infile.open(”Beowulf.txt”);” never man-
aged to open the file. With the Hello World program I kept trying
to initialize integers inside the condition statement of the while
and do while loops but you can really only do that in for loops.
1
3 Answers to Questions
• What are some uses on software in science, medicine, or en-
tertainment?
2
Web Development, Game Design, Computer Modeling, Statis-
tics, and Artificial Intelligence are all applications for com-
puter programming. As a Mathematics major with a fo-
cus in discrete and combinatorial mathematics, I find Com-
puter Modeling the most interesting. Visual representations
of discrete counting methods, shortest-path algorithms and
graph theory are fascinating too me and they can only fea-
sible be made with a strong background in computer pro-
gramming.
4 Sample Output
3
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Do While Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Hello , World !( Using Nested For Loop )
Program ended with exit code : 0
5 Hello World
1 #include <iostream>
2
3 int main(int argc, const char * argv[]) {
4 std::cout << "Hello, World!(Using Single String)\n";
5 for (int i=1; i<=10;i++)
6 {
7 std::cout << "Hello, World!(Using For Loop)\n";
8 }
9 int j=1;
10 while (j<=10){
11 std::cout <<"Hello, World!(Using While Loop)\n";
12 j++;
13 }
14 int k=1;
15 do {
16 std::cout <<"Hello, World!(Using Do While Loop)\n";
17 k++;
18 }
19 while(k<=10);
20 for (int x=1; x<=2;x++)
21 {
4
22 for (int y=1; y<=5;y++)
23 {
24 std::cout << "Hello, World!(Using Nested For Loop)\n";
25 }
26
27 }
28 }
6 Poem
1 #include <iostream>
2 #include <fstream>
3
4 using namespace std;
5 int main(int argc, const char * argv[]) {
6
7 ifstream Infile;
8 Infile.open("/Users/stefanofochesatto/Documents/Documents/cs201/hw0/Poem/Poem Fe
9
10 if (!Infile) {
11 cout << "Unable to open file";
12 exit(1); // terminate with error
13 }
14
15 string x;
16 while (getline(Infile,x)) {
17 cout << x << endl ;
18 }
19 Infile.close();
20 }
7 Game
1 #include <iostream>
2 using namespace std;
3 int main(int argc, const char * argv[]) {
4
5
6
7 cout <<"Nim is a mathematical game of strategy in which two players take turns r
8 cout << "objects from distinct heaps or piles. On each turn, a player must remov
9 cout << "object, and may remove any number of objects provided they all come fro
10 cout << "Depending on the version being played, the goal of the game is either t
11 cout << "object, or to take the last object.";
5
12 return 0;
13 }