0% found this document useful (0 votes)
11 views14 pages

Lab 7

The document contains multiple C++ programming tasks that demonstrate various concepts such as data types, string manipulation, arrays, and matrix operations. Each task includes code snippets that perform specific functions like calculating sizes of data types, comparing string lengths, copying strings, concatenating strings, and manipulating matrices. The tasks are designed to illustrate fundamental programming techniques and operations in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

Lab 7

The document contains multiple C++ programming tasks that demonstrate various concepts such as data types, string manipulation, arrays, and matrix operations. Each task includes code snippets that perform specific functions like calculating sizes of data types, comparing string lengths, copying strings, concatenating strings, and manipulating matrices. The tasks are designed to illustrate fundamental programming techniques and operations in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Task 1:

#include<iostream>

using namespace std;

int main()

cout<<"the size of int is "<<sizeof(int)<<endl;

cout<<"the size of float is "<<sizeof(float)<<endl;

cout<<"the size of double is "<<sizeof(double)<<endl;

cout<<"the size of char is "<<sizeof(char)<<endl;

cout<<"the size of string is "<<sizeof(string)<<endl;

cout<<"the size of long double is "<<sizeof(long double)<<endl;

cout<<"the size of long Int is "<<sizeof (long int)<<endl;

return 0;

}
Task 2:

#include<iostream>

using namespace std;

int main()

int A[4];

float B[6];

char C[8];

double D[9];

string S[2];

long double L[7];

long int I[2];

cout<<"the size of int is "<<sizeof(A)<<endl;

cout<<"the size of float is "<<sizeof(B)<<endl;

cout<<"the size of double is "<<sizeof(D)<<endl;

cout<<"the size of char is "<<sizeof(C)<<endl;

cout<<"the size of string is "<<sizeof(S)<<endl;

cout<<"the size of long double is "<<sizeof(L)<<endl;

cout<<"the size of long Int is "<<sizeof (I)<<endl;

return 0;

}
Task 3:

#include<iostream>

#include<cstring>

using namespace std;

int main()

char A[100],B[100];

cout<<"Enter first string "<<endl;

cin.getline(A,100);

cout<<"Enter second string "<<endl;

cin.getline(B,100);

cout<<"the strings after entered in a character variable are "<<A<<endl;

cout<<"the strings after entered in a character variable are "<<B<<endl;

return 0;
}

Task 4:

#include<iostream>

#include<cstring>

using namespace std;

int main()

char ch[20],ch1[20];

int count=0,count1=0;

cout<<"Enter first string "<<endl;

cin.getline(ch,20);

cout<<"Enter second string "<<endl;

cin.getline(ch1,20);

cout<<"first string "<<ch<<endl;

cout<<"first string "<<ch1<<endl;


int c=strlen(ch);

int b=strlen(ch1);

cout<<c<<endl;

cout<<b<<endl;

if(b>c)

cout<<"the string with more character is second with "<<b<<"characters"<<endl;

else

cout<<"The string with more character is first with "<<c<<"characters"<<endl;

for(int i =0;i<=c;i++)

if(ch[i]=='A'||ch[i]=='E'||ch[i]=='I'||ch[i]=='O'||ch[i]=='U'||ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[
i]=='o'||ch[i]=='u')

count++;

for(int i =0;i<=b;i++)

if(ch1[i]=='A'||ch1[i]=='E'||ch1[i]=='I'||ch1[i]=='O'||ch1[i]=='U'||ch1[i]=='a'||ch1[i]=='e'||ch1[i
]=='i'||ch1[i]=='o'||ch1[i]=='u')

count1++;

cout<<"the vowels in first string are with "<<count<<endl;

cout<<"the vowels in second string are with "<<count1<<endl;


return 0;

Task 5:

#include<iostream>

#include<cstring>

using namespace std;

int main()

char str_1[20],str_2[20];

cout<<"Enter first string "<<endl;


cin.getline(str_1,20);

strcpy(str_2,str_1);

cout<<"First string is "<<str_1<<endl;

cout<<"Second string is copied "<<str_2<<endl;

return 0;

Task 6:

#include<iostream>

#include<cstring>

using namespace std;

int main()

char str_1[20],str_2[5];

cout<<"Enter first string "<<endl;

cin.getline(str_1,20);
strncpy(str_2,str_1,sizeof(str_2)-1);

cout<<"First string is "<<str_1<<endl;

cout<<"Second string is copied "<<str_2<<endl;

cout<<"size of string 2 is "<<sizeof(str_2)<<endl;

return 0;

Task 7:

#include<iostream>

#include<cstring>

using namespace std;

int main()

char str_1[20],str_2[5];

cout<<"Enter first string "<<endl;


cin.getline(str_1,20);

cout<<"Enter second string "<<endl;

cin.getline(str_2,20);

cout<<"the first string is "<<str_1<<endl;

cout<<"the second string is "<<str_2<<endl;

strcat(str_1,str_2);

cout<<"the concatinated string is "<<str_1<<endl;

return 0;

Task 8:

#include<iostream>

#include<cstring>

using namespace std;

int main()
{

char str_1[20];

cout<<"Enter first string "<<endl;

cin.getline(str_1,20);

strlwr(str_1);

cout<<"THE STRING 1 IN LOWER CASE LETTER ARE \n" <<str_1<<endl;

strupr(str_1);

cout<<"THE STRING 1 IN upper CASE LETTER ARE \n" <<str_1<<endl;

return 0;

}
Task 9:

#include <iostream>

using namespace std;

int main()

int mat[3][3],upmat[3][3];

for (int i=0; i<3;i++)

for(int j=0;j<3;j++)

cout<<"Enter a number for matrix \n"<<endl;

cin>>mat[i][j];

for (int i=0; i<3;i++)

for(int j=0;j<3;j++)

cout<<mat[i][j]<<"\t";

cout<<endl;

cout<<"The reversed matrix with respect to row is "<<endl;

for (int i=0,a=0; i<3,a<3;i++,a++)

for(int j=2,b=0;j>=0,b<3;j--,b++)

{
cout<<mat[i][j]<<"\t";

upmat[a][b]=mat[i][j];

cout<<endl;

cout<<"The reversed matrix with respect to column is "<<endl;

for (int i=2; i>=0;i--)

for(int j=0;j<3;j++)

cout<<upmat[i][j]<<"\t";

cout<<endl;

return 0;

}
Task 10:

#include <iostream>

using namespace std;

int main()

char names[10][20];

for (int i=0; i<10;i++)

cout<<"Enter name of student number "<<i<<endl;

cin.getline(names[i],20);

for (int i=0; i<10;i++)

if(names[i][0]=='A'||names[i][0]=='a'||i%2!=0)

cout<<names[i];

cout<<endl;

return 0;

You might also like