#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int max_students=100; //structure defination
struct Student
{
string name;
int roll_no;
char grade;
int attendence;
};
int main()
{
Student students[max_students];
int studentcount=0;
int choice;
LOOP:
cout<<"-------Welcome to Attendence Management System-------"<<endl;
cout<<"--------------Are you Admin or Student---------------"<<endl;
cout<<"1. Admin View"<<endl;
cout<<"2. Student View"<<endl;
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
do{
cout<<"-------Admin View-------"<<endl;
cout<<"1. Add Student"<<endl;
cout<<"2. Mark Attendence"<<endl;
cout<<"3. Display Attendece"<<endl;
cout<<"4. Go back to admin or student selection section"<<endl;
cout<<"5. Exit"<<endl;
cout<<"Enter your choice: ";
cin>>choice;
switch (choice)
{
case 1:
if(studentcount<max_students)
{
cout<<"Enter student name: ";
cin>> students[studentcount].name;
cout<<"Enter roll no: ";
cin>>students[studentcount].roll_no;
cout<<"Enter grade: ";
cin>>students[studentcount].grade;
studentcount++;
cout<<"Student Added Successfully"<<endl;
}
else
{
cout<<"Maximun number of students added"<<endl;
}
break;
case 2:
if(studentcount==0)
{
cout<<"No student to mark Attendence. First add students"<<endl;
}
else
{
int rollnumber;
cout<<"Enter roll no: ";
cin>>rollnumber;
int foundIndex = -1;
for(int i=0;i<studentcount;i++)
{
if(students[i].roll_no==rollnumber)
{
cout<<"Attendence Marked successfully"<<endl;
foundIndex=i;
break;
}
}
if (foundIndex == -1)
{
cout << "Student not found." << endl;
}
}
break;
case 3:
if(studentcount==0){
cout<<"No student to mark Attendence. First add students"<<endl;
}else
{
cout<<"-----Attendence Record---"<<endl;
cout<<setw(20)<<"Name"<<setw(20)<<"Roll_no"<<setw(20)<<"Grade"<<setw(20)<<"Attendence"<<endl;
for(int i=0; i<studentcount; i++){
cout<<setw(20)<<students[i].name<<setw(20)<<students[i].roll_no<<setw(20)<<students[i].grade<<setw(20);
if (students[i].attendence==1)
cout<<"Present"<<endl;
else
cout<<"Absent"<<endl;
}
}
break;
case 4:
goto LOOP;
case 5:
cout<<"Exit the program!Good bye"<<endl;
break;
default:
cout<<"Invalid choice!"<<endl;
}
}
while(choice!=5);
break;
case 2:
do {
cout<<"-------Srudent View-------"<<endl;
cout<<"1. View Attendance\n";
cout<<"2. Exit\n";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice){
case 1:
if(studentcount==0)
{
cout<<"No student to mark Attendence. First add students"<<endl;
}
else
{
for(int i=0;i<studentcount;i++)
{
cout<<students[i].name<<students[i].roll_no<<students[i].grade<<students[i].attendence;
}
}
break;
case 2:
cout<<"Exit the program!Good bye";
break;
default:
cout<<"Invalid choice!";
}
}
while(choice!=2);
break;
}
} Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming language.
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
//code
}
else {
//code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression){
case value1:
// code
break; // optional
case value2:
// code
break; // optional
......
default:
code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}