Quiz3

/*This example will demonstrate how to declare strings and characters.
It will also use the strlen (string length), strcpy (string copy), and
strcat (string concatinate) functions.*/
#include <iostream.h>
#include <string.h>
main()
{   
  char bstg[] = "MNOPQ"; // declaring and assigning a string.
  char cstg[5] = "ABCD";// declaring and assigning a string differently
  /* below, declaring a string with fifteen characters.  The
  characters will be placed in the variables :
  stg[0], stg[1], stg[2]; stg[3]; ...stg[14]*/
  char stg[15];
  /*Declaring a string with 29 characters plus the null at the end of the string*/ 	
  char astg[30];
		
  char ch1; // declaring one character.
  char ch2; // declaring a second character.
  unsigned int stglgth;
	
  cout << bstg << '\n';
  ch1 = bstg [3];// places the 4th character of bstg into ch1
  ch2 = bstg [0];// places the 1st character of bstg into ch2
  bstg[3] = ch2; // places ch2 into the 4th character of the string bstg
  cout << bstg << '\n';
	
  cout << "Enter a string : "; //enter abc
  /*Below, a string of four characters is accepted.  The
  null character will not be inputted but will be placed
  at the end of the string.*/
  cin.get(stg, 5);
	
  /* In the next line, the input stream is being flushed.  
  The 80 tells the program to ignore the next 80 characters in 
  the stream.  The '\n' tells the function to stop ignoring 
  characters when it gets to a carriage return.*/
  cin.ignore(80, '\n');
	
  stglgth = strlen(stg); // finding the length of a string
  cout << stglgth << '\n';
  cout << stg << "***" << stglgth << '\n';
  cout << stg[0] << "****" << stg[1] << "##" << stg[3] << '\n';
  cout << stg[3-1] << "!!" << stg [stglgth - 3] << "!!!\n";
  strcpy(astg, bstg); // copies the string stg into the string astg
  cout << astg << "$$$" << astg[1] << "$$" << astg[0] << '\n';
  cout << strlen(astg) << '\n';
	
  /*below, the strings astg and cstg are concatinated and then
  placed into the string variable astg */
  strcat(astg,cstg); 
	
  cout << "bstg = " << bstg << "astg = " << astg << '\n';
  strcat(stg,astg);
  cout << stg << "***" << astg << "***\n";
  return 0;
}
/*output
MNOPQ
MNOMQ
Enter a string : abc
3
abc***3
a****b##
c!!a!!!
MNOMQ$$$N$$M
5
bstg = MNOMQastg = MNOMQABCD
abcMNOMQABCD***MNOMQABCD***
*/