Angladesh University of Business and Technology: Lab Report-2
Angladesh University of Business and Technology: Lab Report-2
Lab Report-2
Course Name : Compiler Design Lab
Course Code : CSE 324
Submission Date : 26 – 07 – 2023
Submitted To:
Md. Saddam Hossain.
Assistant Professor,
Department of Computer Science & Engineering.
Submitted By:
Name: Tanvirun Islam Anika
ID: 21225103045; Intake: 49; Section: 01
Problem No.1: Input a string from user and determine the length
[without using any built in Function].
Solution code:
#include <iostream>
using namespace std;
int main() {
cout << "Enter a string: ";
char str[100];
cin.getline(str, 100);
int length = 0;
for (length=0; str[length] != '\0'; length++) {
}
cout << "Length of the string: " << length << endl;
return 0;
}
Solution code:
#include <iostream>
using namespace std;
int main() {
char str1[100];
char str2[100];
char result[200];
cout << "Enter the first string: ";
cin.getline(str1, 100);
cout << "Enter the second string: ";
cin.getline(str2, 100);
int i = 0;
while (str1[i] != '\0') {
result[i] = str1[i];
i++;
}
int j = 0;
while (str2[j] != '\0') {
result[i] = str2[j];
i++;
j++; }
result[i] = '\0';
cout << "Concatenated string: " <<result<<endl;
return 0;
}
Solution code:
#include<iostream>
#include<string.h>
using namespace std;
int main(){
string x;
cout<<"Enter string :";
getline(cin,x);
int len=0;
while (x[len]!='\0'){
len++;
}
for(int i=0; i<len; i++){
if(x[i]==' '||x[i]=='.'||x[i]==','||x[i]==';'){
}else{
cout<<x[i];
}
}
return 0;
}