|
|
פתרון/* Module: tr2_q4.cpp Author: Yariv Amar What? This program read 7 characters from the keyboard and prints them as follows: 1. in upside down triangle. 2. prints in one line the ASCII values of the input. Input : seria of 7 characters seprated with spaces; Output: as described . Assumptions on input : valid. How? Algorithm : 1. using "cout" function and "\n" 2. printing charters with casting. */ #include <iostream.h> void main()
{
char Ch1,Ch2,Ch3,Ch4,Ch5,Ch6,Ch7; //define the characthers
const char SPACE=' '; //special char - can be repalced by * or @...
const char NW_LN='\n'; //special char for new_line
//step 1: getting the characters from the user
cout << "Please enter a word with 7 characters :"<<NW_LN;
cout << "======================================="<<NW_LN;
cin >>Ch1>>Ch2>>Ch3>>Ch4>>Ch5>>Ch6>>Ch7;
//step 2: printing the upside down triangle cout <<NW_LN; cout <<Ch1<<SPACE<<Ch2<<SPACE<<Ch3<<SPACE<<Ch4<<NW_LN <<SPACE<<SPACE<<Ch5<<SPACE<<Ch6<<NW_LN <<SPACE<<SPACE<<SPACE<<Ch7<<NW_LN; //step 3: printing ASCI codes cout <<NW_LN; cout << "The ASCII codes for the entered word:"<<NW_LN; cout << "====================================="<<NW_LN; cout <<int(Ch1)<<SPACE<<int(Ch2)<<SPACE<<int(Ch3)<<SPACE<<int(Ch4) <<SPACE<<int(Ch5)<<SPACE<<int(Ch6)<<SPACE<<int(Ch7)<<NW_LN; }
פלטים מיצגיםפלט לדוגמה:
|
|
© Copyright YAProductions 2000 |