LAB 11.docx - CSL-113 Computer Programming Lab Semester BS CS – 01 Exercise 1 Write a C that contains two strings String1= “This program is to test

LAB 11.docx - CSL-113 Computer Programming Lab Semester BS...

This preview shows page 1 - 2 out of 8 pages.

CSL-113: Computer Programming Lab Semester BS CS – 01 Exercise 1 Write a C++ that contains two strings: String1= “This program is to test several string functions”. String2 = “Testing” Perform following operations on these strings: Print a new string “Testing: This program is to test several string function” using concatenation of string 1 and strin2. Find the size of string1 and string2 using string function. Extract word “program” from string1 using string function. Insert a word “Program” in string2 like “Testing Program” using string function. Replace the word “program” in string1 with string2 using string function. Delete word “Program” from string1 using string function Program #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { string String1 = "This program is to test several string functions" ; string String2 = "Testing" ; cout << setfill( '=' ) << setw(103) << "=" << endl; cout << "1)Printing \"This program is to test several string function\"using concentation of string 1 and string 2" << endl; cout << String2 + ": " + String1 << endl; cout << setfill( '=' ) << setw(103) << "=" << endl; cout << "2)Printing size of string 1 and string 2\n" ; cout << "Size of String 1 is " << String1.size() << "\nSize of String 2 is " << String2.size() << endl; cout << setfill( '=' ) << setw(103) << "=" << endl; cout << "3)Printing word program from string 1\n" ; cout << String1.substr(5, 7) << endl; cout << setfill( '=' ) << setw(103) << "=" << endl; cout << "4)Inserting \"Program\" in string 2\n" ; String2.insert(7, " Program" ); cout << String2 << endl; cout << setfill( '=' ) << setw(103) << "=" << endl; cout << "5)Replacing \"program\" in string 1 with string 2\n" ; String1.replace(5, 7, String2); cout << String1 << endl; cout << setfill( '=' ) << setw(103) << "=" << endl; cout << "6)Deleting \"Program\" from string 1\n" ; String1.erase(13, 8); cout << String1 << endl; cout << setfill( '=' ) << setw(103) << "=" << endl; system( "pause" ); return 0; } Department of Computer Sciences Page: 1/8 Semester BSCS 01 CSL-113: Computer Programming Lab Lab 11: String & Structures
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 8 pages?

  • Fall '16
  • Sumaira Kausar

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors