Stuyvesant Computer Programming Club
Project 2
Home
Lessons
Topics Covered
Club Policies
Links
Contact Information
Downloads

Project 2

To recieve credit for the club, you MUST COMPLETE this project.
 
First, please read http://www.cplusplus.com/doc/tutorial/tut3-1.html (the section: Arrays as parameters is optional and you dont have to read it) and http://www.cplusplus.com/doc/tutorial/tut3-2.html (the section: Converting strings to other types is also optional, although helpful).
 
Your assignment will be to write a program that does one of the following:
1. Prompt the user for his first and last name and then print out his full name. For example, the program will ask:
Please enter your first name: *you enter abc*
Please enter your last name: *you enter def*
Your name is abc def.
2. A character counter. The program will prompt the user for a string and an integer (that is less than the string length). The program displays the number of letters in the string and then displays the character with index equal to the index. For example:
Please enter a string: *you enter hello*
Please enter an integer between 0 and 4: *you enter 1*
There are 5 characters in the string.
The character with index 1 is e.
3. Make an array of 4 numbers. Prompt the user for the four numbers. Print out the sum of the numbers. For example:
Please enter number 1: *you enter 1*
Please enter number 2: *you enter 5*
Please enter number 3: *you enter 6*
Please enter number 4 *you enter 2*
The sum is 14.
 
Since number 2 is harder than the rest, I will give you the first half of the code:
#include <iostream.h>
#include <iomanip.h>
#include <string.h>

int main ()
{
  int length;
  char buf [100];
  cout << "Please enter a string: ";
  cin.getline (buf,100);
  length = strlen(buf);
  cout << "Please enter a number between 0 and "<<length-1<<" : ";
  /*Enter the rest of your code here*/
  return 0;
}
 
This project is due at last club meeting. You may print it out or handwrite it. It doesn't really matter. But, if you have to make sure that the program works.
You may also email it to me at psistorm15@yahoo.com and if you email it to me, DO NOT use attachments. just copy and paste your code. And also dont forget to INCLUDE YOUR NAME somewhere in the email.

Enter supporting content here