0% found this document useful (0 votes)
170 views7 pages

Object Oriented Programming Object Oriented Programming Lab 004

This lab report summarizes Dewanand Giri's work on an Object Oriented Programming lab assignment. The report includes 6 programs that perform string operations like converting to uppercase, reversing a string, copying strings, concatenating strings, checking for palindromes, and deleting words from a string. Each program is written in C++ without using library functions to demonstrate skills in object oriented programming.

Uploaded by

Dewanand Giri
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)
170 views7 pages

Object Oriented Programming Object Oriented Programming Lab 004

This lab report summarizes Dewanand Giri's work on an Object Oriented Programming lab assignment. The report includes 6 programs that perform string operations like converting to uppercase, reversing a string, copying strings, concatenating strings, checking for palindromes, and deleting words from a string. Each program is written in C++ without using library functions to demonstrate skills in object oriented programming.

Uploaded by

Dewanand Giri
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/ 7

Lab report of ​Object Oriented Programming

Lab report on: ​Object Oriented Programming


lab 004

BSC CSIT SECOND SEMESTER

Submitted to:​ Jeeban Dhungel


Submitted by:​ Dewanand Giri
Section :​ A
Date :​ 9/21/2020
1. Write a Program to convert string into uppercase without using function.

#include​ ​<iostream>
#include​ ​<string.h>

using​ ​namespace​ std;

int​ ​main​()
{
​string​ ​greeting​;
​int​ ​i​;
​getline​ (​cin​, ​greeting​);
​for​(​i​=​0​;​i​<=​greeting​[​i​]​!=​'​\0​'​;​i​++​)
{
​if​(​greeting​[​i​]​>=​97​ ​&&​ ​greeting​[​i​]​<=​122​)
{
​greeting​[​i​]​=​greeting​[​i​]​-​32​;
}
}
​cout​<<​"​\n​The String in Uppercase = "​<<​greeting​;
​return​ ​0​;
}

2. Write a program to find the reverse of string without using function.

#include <iostream>
#include <string>

using namespace std;

int main()
{
string word,rev;
cout<<"Enter a string: "<<endl;
getline (cin,word);
int i,j,count;
for (i=0;word[i]!='\0';i++)
{
count++;
}
cout<<"Length of string is : "<<count<<endl;
count=count-1;
for (j=0;word[count]!=0;j++)
{
rev[j]=word[count];
cout<<rev[j];
count--;
}

return 0;
}

3.Write a program to copy strings without using function.

#include <iostream>
#include <string>

using namespace std;

int main()
{
string word,copy;
cout<<"Enter a string: "<<endl;
getline (cin,word);
int j;
cout <<"Word you entered: "<<word<<endl;
cout <<"Copied word: "<<endl;

for (j=0;word[j]!='\0';j++)
{
copy[j]=word[j];
cout<<copy[j];
}
return 0;
}

4. Write a program to concatenate string without using library functions:

#include <iostream>
#include <string>

using namespace std;

int main()
{
string source="",copy="",naya;
cout << "Enter a string one" << endl;
getline (cin,source);
cout << "Enter a string two" << endl;
getline (cin,copy);
naya=source+" "+copy;
cout << "New string:" <<naya<<endl;
return 0;
}

5. Write a program to check if a word is palindrome or not without using function.

#include <iostream>
using namespace std;

int main(){
char string1[20];
int i,j,length=0;

int flag = 0;

cout << "Enter a string: "; cin >> string1;


for(i=0;string1[i]!='\0';i++)
{
length++;
}
for(i=0;i < length ;i++){
if(string1[i] != string1[length-i-1]){
flag = 1;
break;
}
}

if (flag) {
cout << string1 << " is not a palindrome" << endl;
}
else {
cout << string1 << " is a palindrome" << endl;
}
return 0;
}

6. Write a program to read a line of text and delete occurrences of particular words.

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int i, j = 0, k = 0;
char str[100], str1[10][20], word[20];
cout<<"\n Enter String : ";
gets(str);
/* Converting the string into Two Dimensional Array */

for (i=0; str[i]!='\0'; i++)


{
if (str[i]==' ')
{
str1[k][j] = '\0';
k++;
j=0;
}
else
{
str1[k][j]=str[i];
j++;
}
}
str1[k][j] = '\0';
cout<<"\n Which Word You Want to Delete? : ";
cin>>word;

/* Comparing the string with the given word */

for (i=0; i<k+1; i++)


{
if (strcmp(str1[i], word) == 0)
{
for (j=i; j<k+1; j++)
{
strcpy(str1[j], str1[j + 1]);
k--;
}
}

}
cout<<"\n New String After Deleting the Word : \n\n";
for (i=0; i<k+1; i++)
{
cout<<" ";
cout<<str1[i]<<" ";
}
return 0;
}

You might also like