You are on page 1of 16

K L UNIVERSITY

FRESHMAN ENGINEERING DEPARTMENT

A Project-Based Lab Report

On

PETER AND TRAIN

SUBMITTED BY:
I.D NUMBER NAME

2100031655 M. Suvarna

2100031656 V. Naveen Raju

2100031657 Mohammad Yaseen

UNDER THE ESTEEMED GUIDANCE OF

T. Ganesan

ASSISTANT PROFESSOR

KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES

CERTIFICATE

This is to certify that the project-based laboratory report entitled


“PETER AND TRAIN” submitted by Mr./Ms. M. SUVARNA bearing Regd. No.
2100021655 to the Department of Basic Engineering Sciences, KL University in partial
fulfillment of the requirements for the completion of a project in “Computational thinking in
structural designing” course in I B Tech II Semester, is a bonafide record of the work carried
out by him/her under my supervision during the academic year 2020-21.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

T. Ganesan Dr. D.HARITHA


ACKNOWLEDGEMENTS

It is great pleasure for me to express my gratitude to our honorable President Sri.


Koneru Satyanarayana, for giving the opportunity and platform with facilities in
accomplishing the project-based laboratory report.

I express the sincere gratitude to our director Dr. A Jagadeesh for his administration
towards our academic growth.

I express sincere gratitude to our Coordinator and HOD-BES Dr. D.Haritha for her
leadership and constant motivation provided in successful completion of our academic
semester. I record it as my privilege to deeply thank for providing us the efficient faculty and
facilities to make our ideas into reality.

I express my sincere thanks to our project supervisor T. Ganesan for his/her novel
association of ideas, encouragement, appreciation and intellectual zeal which motivated us to
venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who devoted


themselves directly or indirectly to make this project report success.

Name: M. Suvarna

Regd . No: 2100031655


ABSTRACT

Peter travels from A to B in a train there are different colored flags ordered between A to B
here peter has two waking points between A to B.

So, in this, there are three lines in input the first line contains a non-empty string where the
characters must not exceed 10*5 the strings contain lower case Latin letters (flag colors from
A to B i.e., forward B to A i.e., backward)

The second line of the input contains the sequence written by peter at 1st period of
wakefulness. The third line of the input contains the sequence written by peter at 2nd period
of wakefulness.

So, then the output is

A to B- forward

B to A- backward

A to B and B to A- both

No sequence -fantasy
INDEX

S.NO TITLE PAGE NO

1. Introduction

2. Aim of the Project

3. Advantages & Disadvantages

4. Future Implementation

5. Software & Hardware Details

6. Class Diagram

7. Implementation

8. Outputs/ScreenShots

9. Conclusion
INTRODUCTION

STRING :

The character data type allows to store a single character only but to store more no of characters
like name of the person, city where he lives were done by using an array of characters is called string

A string is like a sentence with no of words, separated by space hence each and every string is
ended with a string terminator represented by “\0”

DECLARATION OF A STRING:

Char name [SIZE];

LOOPS:

When a block of code needs to be executed several number of times in general statements are
executed sequentially the first statement in a function is executed first, followed by the second, and
so on.

A loop statement allows us to execute or group of statements multiple times given below is the
general form of a loop statement in most of the programming languages.

Loop controls statements change execution from its normal sequence. when execution leaves a
scope, all automatic objects that created in that scope are destroyed.

FOR LOOP

Executes a sequence of statements multiple times and abbreviates the code that manages the loop
variable.

A for loop statement is available in most imperative programming languages .Even ignoring minor
differences in syntax there are many differences in how these statements work and the level of
expressiveness they support .Generally ,for loops fall into one of the following categories.

For (INTILIZATION; CONDITION; INCREMENT/DECREMENT);

//code for the loop body goes here.

7The initialization declares any variables required . The type of a variable should be same if you are
using multiple variables in initialization part. The condition checks a condition, and quits the loop if
false. The after though is performed exactly once every time the loop ends and then repeats
AIM
Peter likes to travel by train. He likes it so much that on the train he falls asleep.

Once in summer, Peter was going by train from city A to city B, and as usual, was sleeping.
Then he woke up, started to look through the window, and noticed that every railway station
has a flag of a particular color.

The boy started to memorize the order of the flags' colors that he had seen. But soon he fell
asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the
colors. Then he fell asleep again, and that time he slept till the end of the journey

At the station, he told his parents about what he was doing and wrote two sequences of the
colors that he had seen before and after his sleep, respectively. Peter's parents know that their
son likes to fantasize. They give you the list of the flags' colors at the stations that the train
passes sequentially on the way from A to B and ask you to find out if Peter could see those
sequences on the way from A to B, or from B to A. Remember, please, that Peter had two
periods of wakefulness.

Peter's parents put lowercase Latin letters for colors. The same letter stands for the same
color, different letters — for different colors.

Advantages: -

1. comfort and accessibility compared to buses, cars, or planes, many trains


are downright luxurious.
2. safety.
3. luggage space.
4. views
5. speed
6. we can relax and read and look out of the window, work, eat.
7. Trains are comfortable if they are not crowded.
Disadvantages: -

1. It is expensive but usually cheaper than traveling by car.

2. It is often crowded.

3. speed.

4.No assigned seating.

5. Close quarters.

6. Lack of control

7. its inflexibility

Future enhancements: -

we can code this program using strings of palindromes.


SYSTEM REQUIREMENTS

 SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language: C
Operating system: Windows XP or later.
Tools: DEV C++
 HARDWARE REQUIREMENTS:

The hardware requirements that map towards the software are as follows:

RAM:16GB

Processor: intel core 5


FLOW CHART
ALGORITHM

STEP 1: START

STEP 2:

Declare 4 variables a, b, c, d

STEP 3: Read three variables a .c .d

STEP 4: Declare two pointers variables p and q

STEP 5: using string function check whether the string “A” is a substring of S or not if found return
the value to pointer PM or return null to the pointer

STEP 6: If STEP 5 is true then check whether the string “B” is a substring of the values stored in p
after removing the string A

STEP 7: Read C. Find the length of c and swap the position of array elements using loop store the
swapped positions in array C

STEP 8: Continue STEP 5 AND STEP 6 using string B has main string and pointer Q and substrings I
and Y

STEP 9:Display both if both P and Q are found and break or

STEP 10: Display backward if only P found and break or

STEP 11: Display backward if only Q is found and break or

STEP 12: Display backward if only Q are found and break or

STEP 13: STOP


IMPLEMENTATION

#include<stdio.h>

#include<string.h>

int match(char text[],char pat1[],char pat2[]);

int revmatch(char text[],char pat1[],char pat2[]);

int main()

int i,j;

char text[100000],pattern1[102],pattern2[102];

scanf("%s",text);

scanf("%s",pattern1);

scanf("%s",pattern2);

int forwardd=0,reversee=0;

if(match(text,pattern1,pattern2)==1)

forwardd=1;

if(revmatch(text,pattern1,pattern2)==1)

reversee=1;

if(forwardd==1 && reversee==0)

printf("forward\n");

else if(forwardd==1 && reversee==1)

printf("both\n");

else if(forwardd==0 && reversee==1)

printf("backward\n");

else if(forwardd==0 && reversee==0)

printf("fantasy\n");

return 0;

}
int match(char text[],char pat1[],char pat2[])

int m=strlen(pat1),n=strlen(text),o=strlen(pat2),x=0;

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

for(int j=0;j<m && i+j<n;j++)

if(text[i+j]!=pat1[j])

break;

if(j==m-1)

i+=m;

for(;i<n;i++)

for(int j=0;j<o && i+j<n;j++)

if(text[i+j]!=pat2[j])

break;

if(j==o-1)

x=1;

return x;

}
}

return x;

int revmatch(char text[],char pat1[],char pat2[])

int m=strlen(pat1),n=strlen(text),o=strlen(pat2),y=0;

for(int i=n-1;i>=0;i--)

for(int j=0;j<m && (i-j)>=0;j++)

if(text[i-j]!=pat1[j])

break;

if(j==m-1)

i-=m;

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

for(int j=0;j<o && (i-j)>=0;j++)

if(text[i-j]!=pat2[j])

break;

if(j==o-1)

y=1;

return y;

}
}

return y;

}
OUTPUTS
CONCLUSION& FUTURE WORK
This project is successfully completed to the extent possible. The results of the project
are shown earlier. By the end of this project, we learned many keywords in c. We learned the strings
concept in c. We are now able to design various types of strings and their functions

You might also like