-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodDocs.cpp
More file actions
90 lines (69 loc) · 2.43 KB
/
GoodDocs.cpp
File metadata and controls
90 lines (69 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//: GoodDocs.cpp
/*
Title: GoodDocs.cpp
Description: Saying Hello with C++
Date: January 3, 2009
Author: Richard S. Huntrods
Version: 1.0
Copyright: 2009 Richard S. Huntrods
*/
/*
DOCUMENTATION
Program Purpose:
Demonstrate proper format for documentation, test plans and comments.
Also demonstrate user prompts, keyboard input, simple calculations and output.
Compile (assuming Cygwin is running): g++ -o GoodDocs GoodDocs.cpp
Execution (assuming Cygwin is running): ./GoodDocs.exe
Notes: in Cygwin, main must return type int
Classes: none
Variables:
name - char array sized for 131 characters - used to store user's name (one word only)
age - int - used to store user's age as an integer number
*/
/*
TEST PLAN
Normal case:
>What is your name? Richard
>What is your age? 21
>Hello! My name is Richard, and I am 21 years old!
>In 10 years, I will be 31 years old!
Bad Data case 1 (more than one name)
>What is your name? Richard Huntrods
>What is your age? 21
>Hello! My name is Richard, and I am 21 years old!
>In 10 years, I will be 31 years old!
Bad Data case 2 (nonsense or non-alpha name)
>What is your name? zb23xx!
>What is your age? 21
>Hello! My name is zb23xx!, and I am 21 years old!
>In 10 years, I will be 31 years old!
Bad Data case 3 (negative age)
>What is your name? Richard
>What is your age? -1
>Hello! My name is Richard, and I am -1 years old!
>In 10 years, I will be 9 years old!
Bad Data case 4 (floating point age)
>What is your name? Richard
>What is your age? 12.5
>Hello! My name is Richard, and I am 12 years old!
>In 10 years, I will be 22 years old!
Discussion:
The program accepts only a single word for the name input (whitespace delimits the word - comma, space, period, etc.)
The program also attempts to convert the age input into an integer, even if this produces a nonsense result (i.e. 'five').
Negative numbers are allowed and processed as if legitimate, and floating point numbers are truncated.
*/
#include <iostream> // Stream declarations
using namespace std;
int main(void) {
char name[132];
int age;
// request and obtain name
cout << "What is your name? ";
cin >> name;
// request and obtain age
cout << "How old are you? ";
cin >> age;
// display output
cout << "Hello! My name is " << name << ", and I am " << age << " years old! " << endl;
cout << "In 10 years, I will be " << (age + 10) << " years old! " << endl;
} ///:~