Strings Manipulation in C++

Strings Manipulation in C++

  • Submitted By: zubair340
  • Date Submitted: 05/09/2011 8:53 AM
  • Category: Technology
  • Words: 1921
  • Page: 8
  • Views: 243

INTERNATIONAL ISLAMIC UNIVERSITY, ISLAMABAD
FACULTY OF BASIC AND APPLIED SCIENCES
DEPARTMENT OF SOFTWARE ENGINEERING

Programming Fundamentals Lab
Spring 2011

Lab Number: 7
Registration: 1124\FBAS\BSSE\F10
Name: ZUBAIR REHMAN DAR
Section: A

PROGRAMMING FUNDAMENTALS CS 111
Spring 2011

EXPERIMENTS

#include <iostream>
using namespace std;
int main()
{
char C[10];
cin>>C;//assume user enters abcdef, explain the output
cout<<C;
return 0;
}

SOLUTION:

In this program we declare a character type array and set its size as 10. In the next line the program get input from user suppose it is “abcdef” and display that input….as a result the same input will be appear on the output screen. There is also a chance that if the input entered by the user is less than 10 characters than the remaining locations of the array contains garbage and at the end of the output garbage is printed………

2) What if the line Char C[10] is replaced with Char C [10]={0}, explain the output now.

#include <iostream>
using namespace std;
int main()
{
char C[10]={0};
cin>>C;//assume user enters abcdef, explain the output
cout<<C;
return 0;
}

SOLUTION:

In this program we declare a character type array and set its size as 10. Then we initialize all the locations of the array as 0. In the next line the program get input from user suppose it is “abcdef” and display that input….as a result the same input will be appear on the output screen.

3)
#include <iostream>
using namespace std;
int main()
{
double distance[] = {44.14, 720.52, 96.08, 468.78, 6.28};
int index = sizeof(distance) / sizeof(double);
cout << "Array members and their values\n"; // Using a for loop to scan an array
for(int i = 0; i < index; ++i)
cout << "Distance : " << i + 1 << distance[i] << endl;
return 0;
}

SOLUTION:

In this program we declare a...

Similar Essays