0% found this document useful (0 votes)
338 views20 pages

Peter and Train

This document contains a report submitted by four students on a project titled "Peter and the Train". It includes sections like introduction, aim of the project, advantages and disadvantages, future implementation, software and hardware details, flow diagram, algorithm implementation, implementation, integration and system testing, and conclusion. The report is certified by the project supervisor and head of the department. It also includes acknowledgements and an abstract of the project.
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)
338 views20 pages

Peter and Train

This document contains a report submitted by four students on a project titled "Peter and the Train". It includes sections like introduction, aim of the project, advantages and disadvantages, future implementation, software and hardware details, flow diagram, algorithm implementation, implementation, integration and system testing, and conclusion. The report is certified by the project supervisor and head of the department. It also includes acknowledgements and an abstract of the project.
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/ 20

Koneru Lakshmaiah Education Foundation

(Deemed to be University)

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab
Report On
PETER AND TRAIN
SUBMITTED BY:

ID NUMBER NAME

2200030214 Y.Bindu Bharghavi


2200030267 G.Sai SivaRama Krishna Prasad
2200030339 T.Sai Sushma
2200030341 CH.Gnana Prasunna

UNDER THE ESTEEMED GUIDANCE OF

N. SREE RAM
Associate 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 THE TRAIN”submitted by“G.Prasad, Y.Bindu Bharghavi, T.Sai
Sushma, CH.Gnanaprasunna bearing Regd.NO:2200030214,2200030267,
2200030339,2200030341 to the Department of Basic Engineering Sciences-
1,KL University in partial fulfillment of the requirements for the completion
of a project based Laboratory in “Computational Thinking For Structured
Design” course in B Tech I Semester, is a bonafide record of the work carried
out by him/her under my supervision during the academic year 2022 – 2023.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

N.Sree Ram 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 sincere gratitude to our principal Dr.A.Jagadeesh for his
administration towards our academic growth.

I express sincere gratitude to HOD-BES-1 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 Mr.N.Sree Ram 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.

Names: Regd.No:

G. Sai SivaRama Krishna Prasad 2200030267


Y. Bindu Bharghavi 2200030214
T. Sai Sushma 2200030339
CH. Gnana Prasunna 2200030341
ABSTRACT
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 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.
INDEX

S.NO TITLE PAGE NO

1 Introduction 1

2 Aim of the Project 6

2.1 Advantages & Disadvantages 7

2.2 Future Implementation 8

3 Software & Hardware Details 9

4 Flow Diagram 10

5 Algorithm Implementation 11

6 Implementation 12

7 Integration and System Testing 13

8 Conclusion 14
1.INTRODUCTION

C is a procedural programming language. It was initially developed by Dennis


Ritchie between 1969 and 1973. It was mainly developed as a system
programming language to write an operating system. The main features of C
language include low-level access to memory, a simple set of keywords, and
clean style, these features make C language suitable for system programming
like an operating system or compiler development. Many later languages have
borrowed syntax/features directly or indirectly from C language. Like syntax
of Java, PHP, JavaScript and many other languages are mainly based on C
language.

The components of the above structure are:


1.Header Files Inclusion: The first and foremost component is the
inclusion of the Header files in a C program.

A header file is a file with extension .h which contains C function


declarations and macro definitions to be shared between several source
files.
Some of C Header files:

1.stddef.h – Defines several useful types and macros.

2.stdint.h – Defines exact width integer types.

3. stdio.h – Defines core input and output functions

4. stdlib.h – Defines numeric conversion functions, pseudo-random


network generator, memory allocation
5. string.h – Defines string handling functions

6.math.h – Defines common mathematical functions

guage suitable for system programmings like an operating


system or compiler development.

Many later languages have borrowed syntax/features directly or indirectly


from C language. Like syntax of Java, PHP, JavaScript and many other
languages are mainly based on C language. C++ is nearly a superset of C
language (There are few programs that may compile in C, but not in C++.
Beginning with C programming:
1.Structure of a C program
After the above discussion, we can formally assess the structure of a C
program. By
structure, it is meant that any program can be
written in this structure only. Writing a C program in any other structure
will hence lead to a Compilation Error.

The structure of a C program is as follows:

The components of the above structure are:


1) Header Files Inclusion: The first and foremost component is the
inclusion of the Header files in a C program.
2).A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several source files.
Some of C Header files:

1. stddef.h – Defines several useful types and macros.


2. stdint.h – Defines exact width integer types.

3.stdio.h – Defines core input and output functions

4. stdlib.h – Defines numeric conversion functions, pseudo-random


network generator, memory allocation
5. string.h – Defines string handling functions

6.math.h – Defines common mathematical functions

Syntax to include a header file in C:

#include <(header_file_name).h>

2. Main Method Declaration: The next part of a C program is to declare the


main()

function. The syntax to declare the main function is:

Syntax to Declare main method:

int main()

{}

2) Variable Declaration: The next part of any C program is the variable


declaration. It refers to the variables that are to be used in the function.
Please note that in C program, no variable can be used without being
declared. Also in a C program, the variables are to be declared before any
operation in the function.
Example:

int main()

int a;
3. Body: Body of a function in C program, refers to the operations that are
performed in the functions. It can be anything like manipulations, searching,
sorting, printing, etc.
Example:

int main()
{

int a;

printf("%d", a);
2. Return Statement: The last part in any C program is the return statement.
The return statement refers to the returning of the values from a function.
This return statement and return value depend upon the return type of the
function. For example, if the return type is void, then there will be no return
statement. In any other case, there will be a return statement and the return
value will be of the type of the specified return type.
Example:

int main()

int a;

printf("%d", a);

return 0;

}
#include<stdio.h>In a C program, all lines that start with # areprocessed
by pre processor which is a program invoked by the compiler. In a very
basic term, pre processor takes a C program and produces another C
program. The produced program has no lines starting with #, all such lines
are processed by the pre processor. In the above example, pre processor
copies the pre processed code of stdio.h to our file. The .h files are called
header files in C. These header files generally contain declaration of
functions. We need stdio.h for the function printf() used in the program.

int main(void) There must to be starting point from where execution of


compiled C program begins. In C, the execution typically begins with first
line of main(). The void written in brackets indicates that the main doesn’t
take any parameter (See this for more details). main() canbe written to take
parameters also. We will be covering that in future posts.
The int written before main indicates return type of main(). The value
returned by main indicates status of program termination. See this post
for more details on return type.

[ { and } ] In C language, a pair of curly brackets define a scope and


mainly used in functions and control statements like if, else, loops. All
functions must start and end with curly brackets.

[ printf(“Geeks Quiz”); ] printf() is a standard library function to print


something on standard output. The semicolon at the end of printf indicates
line termination. In C, semicolon is always used to indicate end of
statement.

[ return 0; ] The return statement returns the value from main(). The
returned value may be used by operating system to know termination
status of your program. The value 0 typically means successful
termination.
AIM

To show peter and train project using strings concept

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.

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' colors 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 second line contains the sequence, written by Peter during the first period
of wakefulness. 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. Each of the
sequences is written in chronological order.

OUTPUT:
«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.
2.1. ADVANTAGES AND DISADVANTAGES

ADVANTAGES:
• Compilation creates unique strings. At compile time, strings are resolved
as far as possible. This includes applying the concatenation operator and
converting other literals to strings. Compilers differ in their ability to
achieve this resolution. You can always check your compiler (e.g., by
decompiling some statements involving concatenation) and change it if
needed.
• Because String objects are immutable, a substring operation doesn’t need
to copy the entire underlying sequence of characters. Instead, a substring can
use the same char array as the original string and simply refer to a different
start point and endpoint in the char array. This means that substring
operations are efficient, being both fast and conserving of memory; the extra
object is just a wrapper on the same underlying char array with different
pointers into that array.

• Strings have strong support for internationalization. It would take a


large effort to reproduce the internationalization support for an
alternative class.

DISADVANTAGES:
1. Not being able to subclass String means that it is not possible to add
behavior to String for your own needs.
2. The previous point means that all access must be through the restricted
set of currently available String methods, imposing extra overhead.
3. The only way to increase the number of methods allowing efficient
manipulation of String characters is to copy the characters into your own
array and manipulate them directly, in which case String is imposing an
extra step and extra objects you may not need.
4. char arrays are faster to process directly.
5. The tight coupling with String Buffer can lead to unexpectedly high
memory usage. When String Buffer .to String( ) creates a String, the current
underlying array holds the string, regardless of the size of the array (i.e., the
capacity of the String Buffer). For example, a String Buffer with a capacity
of 10,000 characters can build a string of 10 characters. However, that 10-
character String continues to use a 10,000-char array to store the 10
characters. If the String Buffer is now reused to create another 10-character
string, the String Buffer first creates a new internal 10,000-char array to
build the string with; then the new String also uses that 10,000-char array to
store the 10 characters. Obviously, this process can continue indefinitely,
using vast amounts of memory were not expected.

2.2. Future Enhancements

By using linked list we can able to reduce the time complexity along with
some data structures concepts
Another, probably more useful, function for windows would be the ability
for users to easily merge them so that two images or columns of text can be
joined just by moving the windows to the appropriate locations and issuing
simple mouse or keyboard commands. Likewise, it would be useful if users
had simple techniques for cutting windows (and their contents) into multiple
windows.
3. SYSTEM REQUIREMENTS

SOFTWARE REQUIREMENTS:

The major software requirements of the project are as follows:

Language : DEV C++

Operating system: Windows Xp or later.

HARDWARE REQUIREMENTS:

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

RAM : 8GB

Processor : Intel Core Processor(I 7 version)


4.ALGORITHM IMPLEMENTATION

STEP – 1: Start

STEP – 2: read the strings s, s1, s2 and integer flag1and flag2

STEP – 3: Take the helping string “r” and “ch”

STEP – 4: Store the reverse string of ‘s’ in ‘r’

STEP – 5: If strstr(s, s1),

Search string s1in s stored in “ch”

If (strstr(ch+strlen(s1), s2))

Flag 1=1

STEP – 6: If strstr(r, s1)

If (strstr (ch +strlen(s1)), s2)

Flag2=1

STEP – 7: If flag1=1 and flag2=1

Print “both”

Else if flag1=1 and flag2=0

Print “forward”

Else if flag1=0 and flag2=1

Print “backward”

Else if flag1=0 and flag2=0

Print “fantasy”

STEP – 8: stop
6.Implementation

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
char s[105], r[105];
int i,j,k;
char s1[100], s2[100],*ch;
int flag1=0, flag2=0;
scanf("%s%s%s", s,s1,s2);
k=0;
for(i=strlen(s)-1; i>=0; i--)
r[k++] = s[i];
r[k]='\0';
if(strstr(s ,s1))
{
ch=strstr(s, s1);
if(strstr((ch+strlen(s1)), s2))
flag1=1;
}
if(strstr(r, s1))
{
ch=strstr(r, s1);

if(strstr((ch+strlen(s1)), s2))
flag2=1;
}

if(flag1==1&&flag2==1) printf("both\n");
else if(flag1==1&&flag2==0) printf("forward\n");
else if(flag1==0&&flag2==1) printf("backward\n");
else if(flag1==0&&flag2==0) printf("fantasy\n");
return 0;
}
4. INTEGRATION AND SYSTEM TESTING

OUTPUTS
Screen Shots:

5. CONCLUS
8. CONCLUSION

In give project we conclude that we have successfully completed the project


“PETER AND TRAIN”. In a simple way.All these details are entered and
retrieved manually, because of this there are many disadvantages like The only
way to increase the number of methods allowing efficient manipulation of
String characters is to copy the characters into your own array and manipulate
them directly, in which case String is imposing an extra step and extra objects
you may not need. Time Consuming , updating process, inaccuracy of data.
For avoiding this we introduced or proposed a new systemin proposed system
the computerized By using linked list we can able to reduce the time
complexity along with some data structures concepts version of the existing
system provides easy and quick access over the data.
And given all test cases and everything is passed.

You might also like