Saturday, March 18, 2017

C++ Part 31

String.Length

//Demonstrates using a string object as if it were an array.
#include <iostream>
#include <string>
using namespace std;
int main( )
{
   string firstName, lastName;
   cout << "Enter your first and last name:\n";
   cin >> firstName >> lastName;
   cout << "Your last name is spelled:\n";
   int i;
   for (i = 0; i < lastName.length( ); i++)
   {
       cout << lastName[i] << " "; // Printing the last name with a space after that.
       lastName[i] = '-'; // Replacing the LastName with a "-" character. You not see the result yet.
   }
   cout << endl;
   for (i = 0; i < lastName.length( ); i++)
       cout << lastName[i] << " "; //Places a "-" under each letter, and prints a space after theme.
   cout << endl;
   cout << "Good day " << firstName <<"."<< endl;
   return 0;
}

No comments:

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two diļ¬€erent implementations of the same instru...