Lab cs101
Lab cs101
Question 1: -
Define a struct called Book with members for title, author, price, and pages. Write a program to:
• Print out the details of the book with the highest price.
Question 2: -
Create a struct called Point with x and y coordinates. Write a function that takes two Point structs as
parameters and returns the distance between them as a double. Implement the function and test it
with different points.
Question 3: -
Create a struct called Point with x and y coordinates. Write a function that takes two Point structs as
parameters and returns the distance between them as a double. Implement the function and test it
with different points.
Question 4: -
Define a struct Student with members for name, roll_number, and marks (an array to hold marks for
3 subjects). Write a program to:
• Write a function to calculate the average marks of each student and print the name of the
student with the highest average marks.
Question 5: -
Define an enum TrafficLight with values RED, YELLOW, and GREEN. Write a program to take user input
to select a traffic light color and print the action to be taken (e.g., "Stop" for RED, "Caution" for
YELLOW, "Go" for GREEN).
Question 6: -
Write a user-defined function int factorial(int n) that calculates the factorial of a given number n.
Write a program that:
Question 7: -
Write a user-defined function to find the largest number in an array. The function should take an
integer array and its size as parameters and return the largest number. Write a program that:
• Calls the function to find and print the largest number in the array.