Site icon Tutor Bin

University of North Texas Java Worksheet

University of North Texas Java Worksheet

Description

Way back in homework P01, you wrote the classic “Hello, World!” program in Java. Now that we’re learning a

bit about C++, let’s retread that hallowed ground!

Full Credit

For this full credit assignment, we will repeat both the P01 full credit and bonus assignments – in C++!

If you haven’t already, set up your C++ development environment using guidance from Lecture 00 (slides
14-15). Then in cse1325/P08/full_credit, create and run the C++ “Hello, World!” program in file hello.cpp
using std::cout, replacing “World” with your name. Take a screenshot of your program running, and name
it hello_me.png.

Then create and run a C++ program from file hello_all.cpp that asks the user for their name, then prints “Hello,
[name]”, where [name] is the name they enter. Test this at least 3 times – with a single-word name, with a
mult-word name separated by spaces, and by a name with different (potentially weird) characters. Take a
screenshot of your program running all of these tests, and name it hello_all.png. As long as your program
prints something after “Hello, “, you get full credit regardless of the outcome of these 3 or more tests.

Add hello_me.cpp, hello_me.png, hello_all.cpp, and hello_all.png to git, commit, and push to GitHub. Bonus

write a C++ program in file reverse.cpp that prints each of its parameters with the
characters reversed. That is, ./a.out hello world would print olleh dlrow (on one line or separate
lines, your choice).

No screenshots are required.

Hint: std::string has a constructor that will accept a char*.

Hint: std::string is a collection of chars.

Hint: The std::reverse function (from <algorithm>) will reverse a collection in place. To reverse any collection
foo, write std::reverse(foo.begin(), foo.end()); (this rather odd syntax was chosen so that a
subset of a collection could be easily reversed).

Add, commit, and push all files.

Extreme Bonus

write a program in file sorted.cpp that reads all newline-terminated lines of
text from the console until end of file. Then, print all of the lines of text back out sorted in alphabetic order.

No screenshots are required.

Hint: The equivalent of Java’s ArrayList<String> would be the std::vector<std::string> (from

<vector>). Rather than add, use the push_back method, e.g.,

std::vector<std::string> v; v.push_back(“Hi!”);

Hint: std::vector is a collection of objects of the type specified in the angle brackets < >.

Hint: The std::sort function (from <algorithm>) will sort a collection in place. To sort any collection foo, write

std::sort(foo.begin(), foo.end()); (this rather odd syntax was chosen so that a subset of a
collection could be easily sorted).

Hint: You can redirect a text file foo.txt into your program with bash’s < operator, e.g., ./a.out < foo.txt If
you prefer to type the lines of text yourself, you can type an end of file signal using Control-d (for Linux or Mac)
or Control-z (for Windows).

Add, commit, and push all files.


Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Exit mobile version