Professional Documents
Culture Documents
Lab Manual 1 Arifah
Lab Manual 1 Arifah
Lab 1
Tuesday; March 28, 2023
Instructor: Arifah Azhar
Email: arifah.azhar@umt.edu.pk
QUESTION 1
Create a switch based where the user will be prompted again and again to choose the appropriate
question to execute. If he does not wish to make any more executions, he should enter -1.
The menu should properly prompt you about the question number you want to execute. After
successful execution of the question, the menu should be displayed again. In case the question
number is invalid, your program should be able to say so.
page 1 of 6
Self-study time: we ae there to help you, if you ask for it.
You can read more about these libraries from MSDN, your book or the internet.
page 2 of 6
page 3 of 6
2a. What is the output of the following program : [CLO2] [10 minutes]
#include "string.h"
#include "iostream.h"
void main()
{
char S1[100];
char S2[100];
char S3[100];
int a;
strcpy(S3,"AAA");
strcpy(S1,"HELLO ");
strcpy(S2,"THERE ");
cout << "\nFIRST TIME " << "\t S1 = " << S1 << "\t S2 = " << S2 << "\t S3 = " << S3;
strncpy(S2,S3,2);
cout << "\nSECOND TIME " << "\t S1 = " << S1 << "\t S2 = " << S2 << "\t S3 = " << S3;
strncpy(S2,S3,5);
cout << "\nSECOND TIME " << "\t S1 = " << S1 << "\t S2 = " << S2 << "\t S3 = " << S3;
strcat(S3,S1);
cout << "\nTHIRD TIME " << "\t S1 = " << S1 << "\t S2 = " << S2 << "\t S3 = " << S3;
strncat(S3,S1,2);
cout << "\nFOURTH TIME " << "\t S1 = " << S1 << "\t S2 = " << S2 << "\t S3 = " << S3;
strncat(S3,S1,10);
cout << "\nFIFTH TIME " << "\t S1 = " << S1 << "\t S2 = " << S2 << "\t S3 = " << S3;
a = strcmp(S2,S1);
cout << "\nSIXTH TIME " << "\t a = " << a;
a = strcmp(S2,S3);
cout << "\nSEVENTH TIME " << "\t a = " << a;
a = strncmp(S2,S3,3);
cout << "\nEIGHTH TIME " << "\t a = " << a;
a = strncmp(S2,S3,4);
cout << "\nNINTH TIME " << "\t a = " << a;
a = strncmp(S2,S3,8);
cout << "\nTENTH TIME " << "\t a = " << a;
}
page 4 of 6
2b. What is the output of the following piece of code? [CLO 2] [10 minutes]
void main()
{
char str1[SIZE]="\0";
char str2[SIZE]="\0";
char str3[SIZE] = "\0";
int i;
for (i=0;i<'9'-'0'+1;++i)
str1[i] = '9' - i;
for (i=0;i<'9'-'0'+1;++i)
str2[i] = '0' + i;
for (i=0;i<strlen(str1)+strlen(str2);i=i+2)
{ str3[i] = str1[i];
str3[i+1] = str2[i];
}
page 5 of 6
2C. What is stored in S1 for getline for the following inputs [CLO 3] [10 minutes]
char S1[100];
page 6 of 6