Fundamentals of Programming: Lab Report # 12
Fundamentals of Programming: Lab Report # 12
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
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