CSCI 116
Project
#1
Purpose: to become familiar with the process of
editing, compiling, and running a C++ program.
In this project, you will type in a given program, compile and run it, concatenate
the output of the program to your program listing, and print the listing for
turn-in. You need to make sure that you
have mastered this process before the next assignment because you will be
expected to do it for the rest of the projects.
Program objective: This program will ask the user for his or her
name, reverse it, and print it out again.
Instructions:
Type the following program using the program editor, and then save it to
a file. Compile the program, run it, and
capture the output in a file. Append the
file as comments to the source code.
Print out the source code, and hand it in by class time of the due date.
// CSCI 116 Fundamentals of
Programming: C++, Spring 2012
// Program #1: Getting started
// Original Author:
// Modified by: (your name goes
here!)
// Date Due: 30 January 2012
//
// This object of this program is
to verify that we can compile and
// execute programs using a C++
compiler. It asks the user for his
// name and then prints it back
out reversed.
#include <iostream>
#include <cstring>
using namespace
std;
int main()
{
char name[120];
int i;
cout << "Type your name and hit return: ";
// cin.getline instead of cin to handle blanks in name
cin.getline(name, 80);
cout << "Hi, " << name << endl;
cout << "Your name backwards is ";
// now print out in reverse one letter at a time
for (i=(int)strlen(name)-1; i>=0; i--)
cout << name[i];
cout << endl;
cout << "All done now!\n";
// if running in debugger, need cin.get(name[0]) here to see output
return 0;
}