forked from hecker9901/Shoping-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTusharHacktoberfest2
185 lines (151 loc) · 5.34 KB
/
TusharHacktoberfest2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
************************************************* SCHOOL MANAGEMENT PROGRAM IN JAVA ************************************************************
import java.util.ArrayList;
import java.util.Scanner;
class Student {
private int rollNumber;
private String name;
private int age;
private String className;
public Student(int rollNumber, String name, int age, String className) {
this.rollNumber = rollNumber;
this.name = name;
this.age = age;
this.className = className;
}
public int getRollNumber() {
return rollNumber;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getClassName() {
return className;
}
@Override
public String toString() {
return "Roll Number: " + rollNumber + ", Name: " + name + ", Age: " + age + ", Class: " + className;
}
}
public class SchoolManagementSystem {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("School Management System");
System.out.println("1. Add Student");
System.out.println("2. List Students");
System.out.println("3. Exit");
System.out.print("Select an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
System.out.print("Enter Roll Number: ");
int rollNumber = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Name: ");
String name = scanner.nextLine();
System.out.print("Enter Age: ");
int age = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Class: ");
String className = scanner.nextLine();
Student student = new Student(rollNumber, name, age, className);
students.add(student);
System.out.println("Student added successfully!");
break;
case 2:
System.out.println("List of Students:");
for (Student s : students) {
System.out.println(s);
}
break;
case 3:
System.out.println("Exiting the program.");
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
************************************************* SCHOOL MANAGEMENT PROGRAM IN cpp ************************************************************
#include<bits/stdc++.h>
class Student {
private:
int rollNumber;
std::string name;
int age;
std::string className;
public:
Student(int rollNumber, std::string name, int age, std::string className) {
this->rollNumber = rollNumber;
this->name = name;
this->age = age;
this->className = className;
}
int getRollNumber() {
return rollNumber;
}
std::string getName() {
return name;
}
int getAge() {
return age;
}
std::string getClassName() {
return className;
}
void displayStudentInfo() {
std::cout << "Roll Number: " << rollNumber << ", Name: " << name << ", Age: " << age << ", Class: " << className << std::endl;
}
};
int main() {
std::vector<Student> students;
while (true) {
std::cout << "School Management System" << std::endl;
std::cout << "1. Add Student" << std::endl;
std::cout << "2. List Students" << std::endl;
std::cout << "3. Exit" << std::endl;
std::cout << "Select an option: ";
int choice;
std::cin >> choice;
switch (choice) {
case 1: {
std::cout << "Enter Roll Number: ";
int rollNumber;
std::cin >> rollNumber;
std::cin.ignore(); // Consume newline
std::cout << "Enter Name: ";
std::string name;
std::getline(std::cin, name);
std::cout << "Enter Age: ";
int age;
std::cin >> age;
std::cin.ignore(); // Consume newline
std::cout << "Enter Class: ";
std::string className;
std::getline(std::cin, className);
Student student(rollNumber, name, age, className);
students.push_back(student);
std::cout << "Student added successfully!" << std::endl;
break;
}
case 2:
std::cout << "List of Students:" << std::endl;
for (const Student& student : students) {
student.displayStudentInfo();
}
break;
case 3:
std::cout << "Exiting the program." << std::endl;
return 0;
default:
std::cout << "Invalid choice. Please try again." << std::endl;
}
}
return 0;
}