You are on page 1of 26

Heaven’s Light is Our Guide

Rajshahi University of Engineering & Technology

Course Title
(Object Oriented Programming)
Course No.
ECE-1203

Submitted to Submitted by
Rakibul Hassan Anika Tabassum Tuba
Assistant Professor Roll: 2010018
Department of ECE, RUET 1st Year Even Semester

1
1(A)
Title: C++ program to reverse a given string.
Methodology:
1. Start
2. Taking input as a string in variable str from the user
3. Using the reverse function to reverse the string. Here in the reverse function
the beginning and the ending of the string must be given in the parenthesis
to reverse the string.
4. Stop
5. Print the reverse string.
CODE:
Input:
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
string str;
getline(cin,str);
cout<< "The String is: ";
cout<<str<<endl;

reverse(str.begin(),str.end());
cout<<"The reverse String is: ";
cout<<str<<endl;
}

Output:

2
Result & Discussion:
Found some complications to find the beginning and the ending letter of the given
string And solved the complication by using the fiunction string.begin() &
string.end().

Title: C++ program to reverse a given string.


Methodology:
1. Taking input a string in variable word from the user.
2. Displaying a given string input.
3. Converting String to StringBuilder object.
4. Reversing StringBuilder object using reverse() method.
5. Converting StringBuilder to String and displaying reversed String.
CODE:
Input:

3
Output:

Result & Discussion:


It is easy to reverse any string using the stringbuilder reverse function.

2(A)
Title: C++ program to capitalize the first letter of each word of a given string.
Methodology:
1. Start
2. Taking Input a sentence as a string in variable str. And for taking a
word as a input we can use cin>>str. But to take input a sentence thr function
getline should be used.
3. A loop has to be taken which will start from the beginning of the first
letter of the string to the length of the string.
4. A funtion toupper() is used to capitalize but a condition must be given
so that all the letters not be capitalize.
5. To capitalize the first letter of the first word of the string the condition
will be if the first index is 0 then the funtion toupper() will be executed.
4
6. And if any gap is found in the sentence the next index of the string will
be capitalized executing the toupper() function because the after the gap the next
index will be the first letter of another word.

Code:
Input:

Output:

5
Result & Discussion:
The program is easily executed by using the toupper() function without any
complication.

Title: Java program to capitalize the first letter of each word of a given string.
Methodology:
1. Taking a sentence as input from the user and store in the variable sen.
2. To scan input it is must to import the class java.util.scanner because the
scanner class is not static.
3. Displaying the sentence which the user inputs.
4. To operate the index of the sentence a string array is taken where the
sentence is splitted.
5. A loop is created which will start from the first index to the length of the
array.
6. A character will be declared where the character of first index of the string
will be returned. And a string will be declared where the declared character
will be kept being capitalized using the function touppercase().
7. The next index to the last index of a word will be kept into another declared
string using the function substring.
8. The capitalized letter and the others letter in the new string will be displayed
together .
9. The process 6 will be continued until the ending of the sentence.

Code:

6
Input:

Output:

Result & Discussion:


If in the print function the space is not declared all the words displayed together
and can’t find the proper sentence. To remove the problem after adding the
capitalized letter and the others letter of a word, a space is written so that a proper
sentence is displayed.

7
1(C)
Title: C++ program to find the largest word in a given string.
Methodology:
1. Taking an input as a sentence. And if a user take input a sentence
getline() function should be used.
2. Declaring another string where the user taken input string is kept with a
space to find a word.
3. A loop will be created which will be start from the first index of the string
and will be finished to the length of the string.
4. If any space is found in the string the counting will be increased which
was initialized zero at first. That’s mean before the gap the count is equal
to the number of the letters of a word.
5. A variable is initialized zero which is compared to the count. The count
will be equal to the variable. When the largest word is found the count
will be maximum as well as the variable. And after that value of the
variable will not be changed. So, there can be a condition that if count is
greater than the value of the variable the operation will be executed.
6. In the above condition the variable will be initialize equal to count until
the largest word is found. Another variable was initialized zero at first
which will be equal to the subtraction of current index and the count,
that’s mean it will be the first index of the current word.
7. After that the count will be initialized zero again and the loop will be
continued.
8. The first index of the largest word and the last index of the word will be
displayed using substring.

CODE:

8
Input:

9
Output:

Result & Discussion:


Faced some challenges to find the letters in the word after finding the words in the
sentence. But it is solved after using two different condition in the loop.

Title: Java program to find the largest word in a given string.


Methodology:
1. Taking a sentence as input from the user and store in the variable sen.
2. To scan input it is must to import the class java.util.scanner because
the scanner class is not static.
3. Displaying the sentence which the user inputs.
4. Declaring another string where the user taken input string is kept with
a space to find a word.
5. A loop will be created which will be start from the first index of the
string and will be finished to the length of the string.
6. A character will be declared where the character of first index of the
string will be returned.
7. There’ll be a condition where the character will be added to the new
variable until the character is any space. That variable’ll define a word.

10
8. In other condition another variable will be equal to the word. And if the
largest word is found the new variable will be the answer. And the
condition will be fulfilled if the previous word length is less than the
new variable word length.
9. After the condition the word length will be initialized zero and the loop
continues until found the large word.
10. The largest word is displayed.
CODE:
Input:

11
Output:

Result & Discussion:


It is easy to find the largest word in a sentence as there is function to compare the
length of words. Also, there doesn’t need much variables.

2(A)
Title:
Creating a class named Cloth which have some properties & Making each property
public. Creating an Object cloth1 of the class and printing the Customer name, price
and delivery date of the object cloth1. Now creating an array of 5 objects of Cloth
class and name them clothArr & Assigning the value of each 5 Objects. and printing
the total price of 5 cloths.
Methodology:
1. To create a class just class name should be written and to name the
class Cloth has been used.
2. As there is a shop name , the name was put into public class.
3. As the customer, tailor name, type of cloth character type so it is
declared as string and other properties are declared as integer type in
public class.

12
4. To create an object of the class in the main function the class is named
cloth1.
5. To print the customer name, tailor name and the delivery date all the
information of the customer has to be taken. and for that to take input
the string getline function was used and to take input integer cin is
used.
6. To clear the buffer fflush(stdin) is used.
7. The properties are displayed. To print the object named cloth1 has to
be written and then the properties.
8. To create an array named clotharr of 5 objects, the class and then the
array name must have written because in the array the properties in
the class is used.
9. To assign the value of five objects in the array a loop is used which will
run 5 times. And again, to collect the customers information getline and
cin is used. To access the properties of the class the class name in the
array has to be written.
10. To calculate the total price of all 5 objects there is an operation a
variable was initialized 0 before. So, whenever the user inputs the
price, the price is added to the variable.
11. Outside of the loop the total price of 5 objects is displayed.

13
CODE:
Input:

14
Output:

15
16
Result & Discussion:
After creating a class, it is must to create an object to access the properties of the
class. Though we create a class, we’ve to do all the operations in the main
function.

2(B)
Title: Creating a class named cloth which have some properties in private.
Creating 7 (accessor) methods to get each element of the class like
get_Shop_Name(). Creating 7 (accessor) methods to set each element of the class
like set_Customer_name(String name). Creating a public method (implementor)
to get the price per square feet size of each cloth. Create 5 objects of the class,
initialize them and print Customer name, Cloth type and price per square feet.
Incrementing the delivery day by 2 days due to tailor crisis & implementing a
method called increment_delivery_date(int days) .
Methodology:
1. Creating a class named cloth and inside the cloth keeping the properties as
private but to access the properties, it is used get and set methods in
public.
2. The methods are written in the class but the body of the function will be
written in main function.
3. The method of the properties declared in public is
return_type class_name :: method/function_name(parameters) { body }
4. The Bodies of all properties of set and get methods are declared.
5. The price per square feet method is declared in public class but the body is
declared outside the function and it is type casted.
6. There is a function for if the tailor delays the delivery date will be changed.
7. There are some cases if 2 days are delayed:
i. If it is leap year and if the date is February 28, then after 2 days
the date will be 1 march which will be 2 march in non-leap
year.
ii. Dividing then month of 30 days & 31 days.

17
iii. The month of 30 days, the condition is applied such that if 2
days increase, and if the date is 30 or 29, then the delivery
date will be in the next month.
iv. If the month is December and the date is the 30 or 31, then the
delivery date will be in the next year.
v. The rest of the month of 31 days without December, the
month and date will be increased.
8. The variable taken in the private class will be declared as a new variable in
main function. And the new variable will be taken input and using the set
methods the value will be sent into private class.
9. The information of the customers will be displayed.

CODE:

18
Input:

19
20
21
22
Output:

23
Result & Discussion:
Found some complication to write the method of date change also to declare the
set and get methods outside class as it return type is void.

24
2(C)
Title: A way to improve the initialization process and assigning the shop name for
each element once.
Methodology:
1. By using constructor method, the initialization process can be improved.
2. And as the shop name is same in each case so by declaring it static, it can
be used only assigning once.
3. Instead of getting info one by one we can get all info together.
4. Again, we can set all info together.
CODE:
#include <bits/stdc++.h>
using namespace std;
class cloth
{
private:
string static shop_name;
string customer_name ,type_of_cloth , delivery_date, tailor_name;
int cloth_price, cloth_size,delivery_time;
public:
void
all_info()
{
cout << "shop_name: " << shop_name << endl;
cout << "customer_name: " << customer_name << endl;
cout << "type_of_cloth: " << cloth_type << endl;
cout << "delivery_date: " << delivery_date << endl;

25
cout << "tailor_name: " << tailor_name << endl;
cout << "cloth_price: " <<cloth_price << endl;
cout << "cloth_size: " << cloth_size << endl;
}
void
set_all_info(string cst_name, string cloth_type, string dlvry_date, string
tlr_name, double cth_size, double cth_price)
{
customer_name = cst_name;
type_of_cloth = cloth_type;
delivery_date = dlvry_date;
tailor_name = tlr_name;
cloth_size = cth_size;
cloth_price =cth_price;
}
cloth()
{
shop_name = "ECE Fashion Pro.";
}
};
int main()
{
cloth cloth1();
return 0;
}

26

You might also like