You are on page 1of 14

KL UNIVERSITY

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab Report
On

TRAIN AND PETER

SUBMITTED BY

K.RAJIV RATNA 2100032455

UNDER THE ESTEEMED GUIDANCE OF

SHAIK MOHAMMED GOUSE

Assistant Professor

KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India

1
DEPARTMENT OF BASIC ENGINEERING SCIENCES

CERTIFICATE

This is to certify that the project based laboratory report entitled


“TRAIN AND PETER” submitted by Mr./Ms. K.RAJIV RATNA bearing
Regd. No. 2100032455 to the Department of Basic Engineering Sciences,
KL University in partial fulfillment of the requirements for the completion of
a project based Laboratory in “Computational Thinking for Structured Design”
course in I B Tech I Semester, is a bonafide record of the work carried out by
him/her under my supervision during the academic year 2021 – 2022.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

SHAIK MOHAMMED GOUSE Dr. D.HARITHA

2
ACKNOWLEDGEMENTS

It is great pleasure for us 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.

We express the sincere gratitude to our Director Dr. A. Jagdeesh for his
administration towards our academic growth.
We 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.

We express my sincere thanks to our project supervisor Shaik


Mohammed Gouse for 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: K.RAJIV RATNA


Regd . No: 2100032455

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

The boy started to memorize the order of the flags' colours that he had seen. But soon he
fell asleep again. he didn't sleep long, he woke up and went on memorizing the colours.
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 colours 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'
colours 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 colours. The same letter stands for the same
colour, different letters — for different colours.

Input
The input data contains three lines. The first line contains a non-empty string, whose
length does not exceed 105, the string consists of lowercase Latin letters — the flags'
colours at the stations on the way from A to B. On the way from B to A the train passes
the same stations, but in reverse order.. The third line contains the sequence, written
during the second period of wakefulness. Both sequences are non-empty, consist of
lowercase Latin letters, and the length of each does not exceed 100 letters.
Output
Output one of the four words without inverted commas:

• «forward» — if Peter could see such sequences only on the way from A to B;
• «backward» — if Peter could see such sequences on the way from B to A;
• «both» — if Peter could see such sequences both on the way from A to B, and on the
way from B to A;
• «fantasy» — if Peter could not see such sequences.

4
INDEX
S.NO TITLE PAGE NO

1 Introduction 6

2 Aim of the Project 7


2.1 Advantages & Disadvantages 7
2.2 Future Implementation 7
3 Software & Hardware Details 8
4 Algorithm for each module 9
5 Implementation 10-12
6 Integration and System Testing 13
7 Conclusion 14

5
INTRODUCTION

❖ The project “Train and Peter” is extensively based on the concept of strings.
❖ It also uses for loop and flag variables
❖ The project is to find the order of stations which Peter memorized during his period
of wakefulness
❖ The input of the program is order of stations from destination A to destination B
❖ The next Two inputs are memorizing order of stations which Peter did during his two
periods of wakefulness respectively

6
AIM
❖ The project is to find the order of stations which Peter memorized during his period
of wakefulness.
❖ The elaboration can be done using an example:

aaacaaa - Order of stations from A to B

aca - Memorization during 1st period of wakefulness

aa - Memorization during 2nd period of wakefulness

Output:-
Both – It is the output as “aca” , ”aa” are sub strings of the main string in both forward
and backward ways.

▪ Output should be “Forward” when the substring condition satisfies from left to right
▪ Output should be “Backward” when the substring condition satisfies from right to
left.
▪ Output should be “Fantasy” when none of the above conditions are True

7
SYSTEM REQUIREMENTS

➢ SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C or Dev C++
Operating system: Windows Xp or later.

➢ HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM :4GB & Above

Processor : i3 & Above

8
ALGORITHM

1.Start
2.Initialize four flag variables with 0
3.Read strings as input
▪ Output should be “Forward” when the substring condition satisfies from left to right
▪ Output should be “Backward” when the substring condition satisfies from right to
left.
▪ Output should be “Fantasy” when none of the above conditions are True

5. Stop

9
IMPLEMENTATION

#include<stdio.h>

#include<string.h>

int main() {

long i=0,j=0,k,flag=0,flag2=0,flag3=0,flag4=0,x,y,z;

char T[100020],A[120],B[120];

gets(T);

gets(A);

gets(B);

x=strlen(T);

y=strlen(A);

z=strlen(B);

for(i=0;i<x;i++)

k = i;

for(j=0;j<y&&flag==0&&T[k]!='\0';j++,k++)

if(A[j] != T[k])

flag = 0;

break; }

if(j == y - 1)

flag = 1;

};

k = i +y;

10
for(j = 0; j <z&& flag2 == 0 && flag == 1&& T[k] != '\0'; j++)

if(B[j] != T[k])

flag2 = 0;

break; }

if(j == z - 1)

flag2 = 1;

k++;

for(i =x- 1; i > -1; i--)

k = i;

for(j = 0; j <y&& flag3 == 0 && k > -1; j++)

if(A[j] != T[k])

flag3 = 0;

break; }

if(j ==y- 1)

flag3 = 1;

k--; }

k = i -y;

for(j = 0; j <z&& flag4 == 0 && flag3 == 1 && k > -1; j++)

11
{

if(B[j] != T[k])

flag4 = 0;

break; }

if(j == z- 1)

{ flag4 =

1;

k--;

if(flag == 1 && flag2 == 1 && flag3 == 1 && flag4 == 1)

printf("both");

else if(flag == 1 && flag2 == 1)

printf("forward");

else if(flag3 == 1 && flag4 == 1)

printf("backward");

else {

printf("fantasy");

return 0;

12
INTEGRATION AND SYSTEM TESTING
Output Screen Shots:

13
CONCLUSION
❖ Thus we can Conclude that the order of Memorization of
stations by peter can be easily calculated using the
concepts of Loops and Strings .

14

You might also like