Вы находитесь на странице: 1из 8

CS10-2L Computer Fundamentals and Programming Laboratory

Laboratory Exercise 3 (Iterative Program Structure) Date


Name Section

File Name Format: LE3_Surname.doc or LE3_Surname.docx

1.) Create a C++ program that will input 10 alphabetic characters and output how many of the
characters entered were vowels and consonants. Display an error message if the character
entered is INVALID.

Sample Output: Input ten alphabetic characters (A-Z or a-z):


Q
e
w
R
o
s
A
d
t
Y
Number of Vowels Entered = 3
Number of Consonants Entered = 7

Press any key to continue or X/x to exit. S

Input ten alphabetic characters (A-Z or a-z):


A
E
I
O
U
#
# is an INVALID character! Input a VALID character.
C
V
N
G
J
Number of Vowels Entered = 5
Number of Consonants Entered = 5

Press any key to continue or X/x to exit. X


2.) Create a C++ program that will input 6 score for quizzes (0-100). Eliminate the lowest quiz and
compute and output the average of the five remaining quizzes.

Sample Output: Input score for 6 Quizzes (0-100):


100
80
50
85
90
95
The average of the five remaining Quizzes = 90
Press any key to continue or X/x to exit. Y

Input score for 6 Quizzes (0-100):


200
200 is INVALID! Input a valid score.
60
80
50
85
90
95
The average of the five remaining Quizzes = 82
Press any key to continue or X/x to exit. A

Input score for 6 Quizzes (0-100):


88
100
70
70
88
90

The average of the five remaining Quizzes = 87.2


Press any key to continue or X/x to exit. X
Laboratory Exercise Score Sheet

Criteria Score

1.1) Neatness and Correctness of Flowchart 15


1.2) Proper Indention of C++ program 5
1.3) Intelligent/Descriptive naming of variables 3
1.4) Informs the User what to input 5
1.5) Correct Process (Condition and Formula) 15
1.6) Correct Output 5
2.1) Neatness and Correctness of Flowchart 15
2.2) Proper Indention of C++ program 5
2.3) Intelligent/Descriptive naming of variables 2
2.4) Correct Process (Condition and Formula) 15
2.5) Correct Output 5
3.) Exercise finished/submitted within time-frame 10

Total 100

_______________________ _______________
Engr. Cristina A. Pascua Date
CS10-2L Computer Fundamentals and Programming Laboratory

Laboratory Exercise 3 (Iterative Program Structure) Date


Name Section

File Name:

Answer Sheet:

1.) C++ Program

#include <iostream>
#include <cctype> // to enbale the lowercase and the uppoercase values
#include <windows.h> // to enable the cls function

using namespace std;


int main ()
{
char alpha, tryagain; // declarations
int ctr, ctrvowel, ctrcons ; // declarations

do
{
system ("cls"); // to clear after the loop
cout << "This Program allows the user to input Aphanumeric characters
and determine" << endl;
cout << "how many consonant and vowels there are" << endl;
cout << "and will indicate if it is invalid."<<endl;
cout << endl << "Please enter 10 Alphanumeric Characters: " << endl;
ctr=1; //counter
ctrvowel=0; // counter for vowel
ctrcons=0; // counter for consonant

for(alpha >= 'A' && alpha <= 'A', ctr=1, ctrvowel=0, ctrcons=0; ctr<=10; ctr++)
{ cin>>alpha;
alpha = toupper (alpha);
if(alpha == 'A' || alpha == 'E' || alpha == 'I' || alpha == 'O' || alpha == 'U')
ctrvowel++; // to count how many vowels
else if (alpha >= 'A' && alpha <= 'Z')
ctrcons++; // to count how many consonants
else
cout << "Invalid" << endl; // if the character is invalid
}
cout<<"Vowel = "<<ctrvowel<<endl;
cout<<"Consonant = "<<ctrcons<<endl;

}
while(tryagain=='Y'); // to loop the program
cout<<"Do you want to try again? [Y/y] ";
cin>>tryagain;
tryagain = toupper(tryagain);

FLOWCHART
START

Declarations
Char alpha, tryagain
Num ctr, ctrvowel, ctrcons

ctr=1;
ctrvowel=
0;
ctrcons=0;

Input Letter

if(alpha == 'A' ||
alpha == 'E' || ctrvowel = ctrvowel++ B
alpha == 'I' ||
alpha == 'O' || Y
alpha == 'U')

C
else if (alpha >= 'A' ctrvowel = ctrvowel++ B
&& alpha <= 'Z')
Y

Output
Invalid

ctr = ctr++ B

Y
for A
ctr <= 10

Output
ctrvowel, Stop
ctrcons
2.) C++ Program

Вам также может понравиться