0% found this document useful (0 votes)
7 views

C_Programming_Lab_Record_AJAY[1]

Uploaded by

Parth Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C_Programming_Lab_Record_AJAY[1]

Uploaded by

Parth Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

DEPARTMENT OF MECHANICAL ENGINEERING

23MEE101 PROBLEM SOLVING USING C

Laboratory Record

First Semester

B Tech. Mechanical Engineering

Name

THAKUR AJAY SINGH

Roll No : AM.EN.U4MEE24063

AMRITA SCHOOL OF ENGINEERING

AMRITA VISHWA VIDYAPEETHAM

AMRITAPURI CAMPUS, CLAPPANA P.O.

KERALA, INDIA 690 525

1
INDEX

Signature of in-
Sl.No Date Experiment
charge

1 08/08/24 LAB SHEET 1

2 22/08/24 LAB SHEET 2

3 29/08/24 LAB SHEET 3

4 12/09/24 LAB SHEET 4

5 19/09/24 LAB SHEET 5

6 26/09/24 LAB SHEET 6

7 10/10/24 LAB SHEET 7

8 17/10/24 LAB SHEET 8

9 14/11/24 LAB SHEET 9

10 21/11/24 LAB SHEET 10

2
LAB SHEET 1
INTRODUCTION TO THE C LANGUAGE

Print the message “Nothing” and explain C programming language.

C is a high-performance, general-purpose programming


language known for its efficiency and low-level memory
access. It's widely used in system programming and
embedded systems. C provides structured programming
with functions, loops, and pointers, offering control over
hardware and system resources.

3
LAB SHEET 2
STRUCTURE OF C PROGRAM

Calculate the area and circumference of a circle

4
LAB SHEET 3
STRUCTURE OF C PROGRAM (Loops)
Program to calculate the sum of first n natural numbers using for loop.

5
LAB SHEET 4
STRUCTURE OF C PROGRAM (Loops cont.)
Display the pattern of a Half Pyramid of *
*
**
***
****
*****

6
LAB SHEET 5
STANDARD LIBRARY FUNCTION
Calculate cube of a number with separate function cube.

7
LAB SHEET 6
USER DEFINED FUNCTIONS
Write a C program to calculate y+z by using user defined function.

8
LAB SHEET 7
RECURSION
Write a program in C to print the first 20 natural numbers using recursion.

9
LAB SHEET 8
ARRAY
Write a program to find the average of n (where n < 15) numbers using arrays.

10
LAB SHEET 9
POINTERS
Write a program in C to swap two numbers using pointers.

11
LAB SHEET 10
PROJECT MANAGEMENT SYSTEM

Introduction
Parking management is a critical aspect of urban infrastructure, particularly in places
with limited space, such as commercial buildings, office complexes, and residential
areas. Managing parking efficiently can improve the overall experience for both
customers and facility owners, ensuring that vehicles are parked in designated spots
and that the system is easily accessible.
This project presents a Parking Management System implemented in C, which is
designed to allocate parking slots based on the type of vehicle (two-wheeler or four-
wheeler) and the user's status (customer or faculty). The system asks the user for the
duration of parking and calculates the parking fee based on that duration. It also
manages parking slots, ensuring that slots for customers and faculty are handled
separately, thereby optimizing space allocation.
The system has been designed to be simple and user-friendly, utilizing basic control
flow and input/output operations in C. It also includes logic to ensure that users are
not allowed to park beyond a certain limit, with the program handling different
scenarios for customers and faculty parking needs.

Problem statement
In many parking systems, managing parking slots and calculating fees for customers
can be a complicated task, especially when dealing with different categories of users
(e.g., faculty, customers). Existing parking management systems often lack a simple
interface or efficient allocation methods for users with different needs. This leads to
inefficient parking space usage and makes it harder to calculate accurate parking
fees.
The current problem involves:
1. Limited Space Management: The system must handle two different types of
vehicles—two-wheelers and four-wheelers—with separate slots for faculty
and customers.
2. Fee Calculation: For customers, the parking fees depend on the duration of
parking, with different rates for two-wheelers and four-wheelers.

12
3. System Interaction: There is a need for a simple interface that guides the user
through choosing their vehicle type and parking duration, while also managing
faculty parking slots separately.
4. Validation of Inputs: Ensuring that users provide valid inputs and that the
system correctly handles edge cases like exceeding parking time limits or
choosing invalid vehicle types.
The goal of this project is to develop a parking system that can manage these
different aspects effectively, making parking easier for both customers and faculty
while ensuring that resources are used efficiently.

Proposed system
The proposed system is a Parking Management System that will manage parking
slots for two types of users: customers and faculty. It will handle two types of
vehicles: two-wheelers and four-wheelers, with different parking rates depending on
the duration of parking. Faculty members will have dedicated parking slots, separate
from those assigned to customers.
The system operates as follows:
 Customer Parking: The system will prompt the user to input the duration of
parking and the type of vehicle (two-wheeler or four-wheeler). Based on the
duration, the system will calculate the parking fee and assign an available
parking slot to the vehicle. If the duration exceeds the allowed maximum (9
hours), the system will reject the parking request.
 Faculty Parking: Faculty members will have dedicated parking slots for both
two-wheelers and four-wheelers. The system assigns a slot to the faculty
member and increments the slot number for future use.
Key features of the proposed system:
1. Slot Assignment: For each user, the system assigns an appropriate parking
slot, incrementing slot numbers for the next user.
2. Fee Calculation: Parking fees are calculated based on the duration of parking
for customers, with different rates for two-wheelers and four-wheelers.
3. User Validation: The system ensures that valid choices are made by the user
(e.g., valid vehicle types, valid parking duration).
4. Simple Interface: The system operates with a simple text-based interface,
guiding the user through the steps of choosing vehicle type, parking duration,
and processing their request.
13
The system is implemented in C, which allows for efficient memory usage and control
over hardware resources. The expected outcome is to provide a simple yet effective
parking management solution, suitable for small-scale environments like office
buildings or residential complexes. The system will be tested for various use cases,
including edge cases where the parking duration exceeds limits or invalid inputs are
provided.

14
Code implementation
#include <stdio.h>

int main() {
int facultytwowheeler = 1, facultyfourwheeler = 21, twoWheelerSlot = 51, fourWheelerSlot = 251;
char nextCustomer;

do {
printf("1. Customer or 2. Faculty\n");
int choice;

printf("Enter the choice according to menu: ");


scanf("%d", &choice);

if (choice == 1) {
int hour, ch;

printf("Enter the duration of parking: ");


scanf("%d", &hour);

printf("1. Two wheeler or 2. Four wheeler\n");


printf("Are you using a two wheeler or a four wheeler? ");
scanf("%d", &ch);

if (ch == 1) {
if (twoWheelerSlot > 250) {
printf("No more slots available\n");
} else{
if (hour < 1 || hour == 1 || hour == 2 || hour == 3) {
printf("You have to pay 15 rupees and park in %dth slot\n", twoWheelerSlot);
} else if (hour == 4 || hour == 5 || hour == 6) {
printf("You have to pay 30 rupees and park in %dth slot\n", twoWheelerSlot);
} else if (hour == 7 || hour == 8 || hour == 9) {
printf("You have to pay 50 rupees and park in %dth slot\n", twoWheelerSlot);
} else {
printf("You cannot park your vehicle for more than 9 hours. Pay 50 rupees and park in
%dth slot\n", twoWheelerSlot);
}
twoWheelerSlot++;
}
}
else if (ch == 2) {
if (fourWheelerSlot > 500) {
printf("No more slots available\n");
} else {
if (hour < 1 || hour == 1 || hour == 2 || hour == 3) {
printf("You have to pay 20 rupees and park in %dth slot\n", fourWheelerSlot);
} else if (hour == 4 || hour == 5 || hour == 6) {
printf("You have to pay 40 rupees and park in %dth slot\n", fourWheelerSlot);
} else if (hour == 7 || hour == 8 || hour == 9) {
printf("You have to pay 70 rupees and park in %dth slot\n", fourWheelerSlot);
15
} else {
printf("You cannot park your vehicle for more than 9 hours. Pay 70 rupees and park in
%dth slot\n", fourWheelerSlot);
}
fourWheelerSlot++;
}
}
else {
printf("Invalid choice. Please enter a valid choice.\n");
}
}
else if (choice == 2) {
int chr;
printf("1. Two wheeler or 2. Four wheeler\n");
printf("Are you using two wheeler or four wheeler? ");
scanf("%d", &chr);

if (chr == 1) {
printf("You can park in %dth slot\n", facultytwowheeler);
if (facultytwowheeler > 20) {
printf("No more slots available\n");
} else {
facultytwowheeler++;
}
}
else if (chr == 2) {
printf("You can park in %dth slot\n", facultyfourwheeler);
if (facultyfourwheeler > 50) {
printf("No more slots available\n");
} else {
facultyfourwheeler++;
}
}
else {
printf("Invalid choice. Please enter a valid choice.\n");
}
}
else {
printf("Invalid choice. Please enter a valid choice.\n");
}

printf("\nDo you want to process for the next customer? (y/n): ");
scanf(" %c", &nextCustomer);

} while (nextCustomer == 'y' || nextCustomer == 'Y');

printf("Thank you for using the parking system. Goodbye!\n");

return 0;
}

16
Output

17

You might also like