Answer to Question #220902 in C for abhi

Question #220902

Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Write an array of 10 students in the collage. Write two functions; one for input, second for output and determine following in main() (a) write a program to print names of all students who joined in a particular year. (b) Write a program to print the data of a student whose roll number is given assignment


1
Expert's answer
2021-07-28T02:59:35-0400
#define _CRT_SECURE_NO_WARNINGS //runtime complie
#define SIZE 3 //size of array
#include <stdio.h>//standart input output
#include <stdlib.h>//standart lib
#include <string.h>//libraru for string function and ...
#include <malloc.h>
//Imnplement structure Student

typedef struct Student
{
	int rolNum;//RollNumber
	char name[50];//Name
	char depart[30];//Departament
	int course;//Course
	int yaer;
}Student;
//Input Function
void InputStudent(Student* st)
{
	printf("RollNumber: ");
	scanf("%i", &st->rolNum);
	printf("Name: ");
	scanf("\n");
	fgets(st->name, 50, stdin);
	printf("Departament: ");
	scanf("%s", st->depart);
	printf("Course: ");
	scanf("%i", &st->course);
	printf("Join Year: ");
	scanf("%i", &st->yaer);
}
//Out function
void OutStudent(Student* st)
{
	printf("RollNumber:  %i       ", st->rolNum);
	printf("Name: %s",st->name);
	printf("Departament: %s    ",st->depart);
	printf("Course: %i      ", st->course);
	printf("Join Year: %i\n",st->yaer);
}
int main()
{
	Student* sArr = (Student*)malloc(sizeof(Student) * SIZE);//array of student
	printf("Please fill date students\n");
	for (int i = 0; i < SIZE; i++)
		InputStudent(&sArr[i]);
	int qu = 0;
	while (!qu)
	{
		printf("Menu\n");
		printf("\t1 -Part (a)-Students joined by particular year\n");
		printf("\t2 -Part (b)-Students by rollNumber\n");
		printf("\t3 Quit\n");
		int cmd;
		scanf("%i", &cmd);
		switch (cmd)
		{
		case 1:
		{
			int yr;//Year
			printf("Please enter joined year: ");
			scanf("%i", &yr);
			for (int i = 0; i < SIZE; i++)
			{
				if (sArr[i].yaer == yr)
				{
					printf("==============OUT DATE STUDENT======================\n");
					OutStudent(&sArr[i]);
				}
			}
			break;
		}
		case 2:
		{
			int rlNum;
			printf("Please enter Roll Number: ");
			scanf("%i", &rlNum);
			for (int i = 0; i < SIZE; i++)
			{
				if (sArr[i].rolNum == rlNum)
				{
					printf("==============OUT DATE STUDENT======================\n");
					OutStudent(&sArr[i]);
				}
			}
			break;
		}
		case 3:
		{
			printf("Quit this programm!!!\n");
			qu = 1;
			break;
		}
		default:
			break;
		}
	}
	free(sArr);//free memory
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS