Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views1 page

Programming Fundamental Assignment No 2: Program No 1: Program No 2

Program 1 initializes a character variable 'ch' to 'a' outside the loop. It uses getche() inside the loop to read characters and cout before the loop to output a string. The character count output subtracts 1 due to initializing 'ch'. Program 2 does not initialize the character variable. It defines the character read inside the loop test expression. It does not use cout to output a string. The character count output is not subtracted since 'ch' is not initialized.

Uploaded by

Hassan Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views1 page

Programming Fundamental Assignment No 2: Program No 1: Program No 2

Program 1 initializes a character variable 'ch' to 'a' outside the loop. It uses getche() inside the loop to read characters and cout before the loop to output a string. The character count output subtracts 1 due to initializing 'ch'. Program 2 does not initialize the character variable. It defines the character read inside the loop test expression. It does not use cout to output a string. The character count output is not subtracted since 'ch' is not initialized.

Uploaded by

Hassan Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Programming Fundamental

Assignment no 2

Program no 1: Program no 2:
1. char ch = 'a'; 1. char ch;
Initialize character is provided to program Initialize character is not provided.
To run inside the loop.

2. while( ch !='\r' ) { 2. while( (ch = getche()) !='\r' )


ch = getche(); Character read is defined inside test
……………………………………………………….. expression of loop statement.
}
Character read is defined inside loop.

3. cout << "Enter a phrase: "; 3. This program don’t use cout statement
Output string is used. to use any string.

4. cout << "\nWords=" << wdcount << endl 4. cout << "\nWords=" << wdcount << endl
<< "Letters=" << (chcount-1) << endl; << "Letters=" << chcount << endl;
In output result of character count, it’s General output is taken no subtraction is
subtracted by 1 because of, char ch = 'a'. done, char ch; .

5. Output: 5. Output:
Enter a phrase: Hassan Javed Hassan Javed
Words=2 Words=2
Letters=11 Letters=11
Press any key to continue . . . Press any key to continue . . .

Title: Differentiate between PROGRAM – 01 and PROGRAM – 02.

You might also like