[go: up one dir, main page]

0% found this document useful (0 votes)
561 views4 pages

Fundamentals of Programming: Lab Report # 12

This document contains a lab report submitted by a student. The report details two programming tasks - writing a C++ program to copy a string to another string using string and cstring, and writing a program to concatenate a string without functions using the same. For each task, the student includes the source code and a screenshot of the output.

Uploaded by

salmo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
561 views4 pages

Fundamentals of Programming: Lab Report # 12

This document contains a lab report submitted by a student. The report details two programming tasks - writing a C++ program to copy a string to another string using string and cstring, and writing a program to concatenate a string without functions using the same. For each task, the student includes the source code and a screenshot of the output.

Uploaded by

salmo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 4

COMPUTER SCIENCE DEPARTMENT

Fundamentals of
Programming
(LAB)
Lab Report # 12

Submitted To:

Student Name:

Reg. Number:

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 4

Task (01):
Write a C++ program that takes an input string and copies it to
another string (Using both cstring and string class).

Source Code:
1. #include <iostream>  
2. #include <string>  
3. using namespace std;  
4. int main()  
5. {  
6.     string first_name;  
7.     string second_name;  
8.     string full_name;  
9.     int len;     
10. first_name = second_name;  
11. cout<<"Enter Your first_name "<<first_name<<endl;  
12. cin>> first_name;  
13.   
14. cout<<"Enter Your second_name "<<second_name<<endl;  
15. cin>> second_name;  
16.   
17. full_name = first_name + second_name;  
18. cout<<"first_name + second_name:   "<<full_name<<endl;  
19.   
20.       
21.     return 0;  
22. }  

Screenshot of Output:

Task (02):

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 4

Write a C++ program that takes an input string and


concatenates it without using any function (Using both cstring
and string class).

Source Code:
1. #include <iostream>  
2. #include <cstring>  
3. using namespace std;  
4. int main()   
5. {  
6.       
7.     char first_name[10];  
8.     char second_name[10];  
9.     char full_name[20];  
10.     int len;  
11.       
12.       
13.     cout<<"Enter Your first_name:   "<< first_name << endl;  
14.     cin>> first_name;  
15.   
16.     cout<<"Enter Your second_name "<< second_name << endl;  
17.     cin>> second_name;  
18.   
19. //concatenate first_name or second_name  
20.   strcat( first_name , second_name);  
21.   cout<<"full_name:   "<< first_name << endl;  
22.   
23. //Total Lenght of full_name after concatenate first_name and seco
nd name  
24. len = strlen(full_name);  
25. cout<< "Total words in full_name:  "<< len << endl;  
26.       
27.     return 0;  
28. }  

Screenshot of Output:

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 4

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB

You might also like