Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
class attend
{
        float p=0,t=0,w;
        public:
                int enter();
                void calculate();
};
int attend::enter()//update the attendance 
{
        int date,month,year;
        int i,n,k,a,c;
        int z[20];
        cout<<">>ENTER ANY KEY TO GIVE THE DATE... "<<endl;
        cin>>i;
        while(i)
        {
        	cout<<"->Enter DATE/MONTH/YEAR: "<<endl;
        	cin>>date>>month>>year;
        	cout<<endl;
                if(month== 1||month==3||month==5||month==7||month==8||month==10||month==12)
                {
                		if(date>31||date==0)
                		{
							c=0;
						}
						else
						{
							 c=1;
						}
                }
                if(month== 4||month==6||month==9||month==11)
                {
                	if(date>30 ||date==0)
                	{
                		 c=0;
                	}
                	else
                	{
                		 c=1;
                	}
                }
                if(month==2)
                {
                	if(date>29||date==0)
                	{
                		 c=0;
                	}
                	else
                	{
                		 c=1;
                	}
                }
                if(month>12)
                {
                	c=0;
                }
                if(month==0||year==0)
				{
					c=0;
				}
                switch(c)//gives if the given date is correct or not and update
                {
                	case 0:cout<<"Please enter::VALID DATE::"<<endl<<endl;
                			break;
               		 case 1:			
               			 cout<<">>ENTER NUMBER OF PERIODS IN THE DAY...(max periods=7): ";
                		cin>>n;
                		cout<<endl;
                		for(k=1;k<n+1;k++)
                		{
                    	    cout<<"->ENTER '1' IF PRESENT ELSE '0' TO UPDATE THE STATUS OF PERIOD "<<k<<" :";
                    	    cin>>a;
                    	    if(a==1)
                    	    {
                    	            p++;
                        	        t++;
                        	        z[k]=1;
                        	        cout<<"   ......................................................................"<<endl<<endl;
                            	    cout<<"                         :::UPDATED AS PRESENT:::"<<endl<<endl;
                            	    cout<<"   ......................................................................"<<endl<<endl;
                        	}
                			else
                        	{
                        	        t++;
                        	        z[k]=0;
                        	        cout<<"   ......................................................................"<<endl<<endl;
                        	        cout<<"                          :::UPDATED AS ABSENT:::"<<endl<<endl;
                        	        cout<<"   ......................................................................"<<endl<<endl;
                        	}
                		}
                		cout<<endl;
                		cout<<"                    ::::::ATTENDANCE OF THE DAY IS UPDATED AS:::::"<<endl;
                		for(k=1;k<n+1;k++)
                		{
                			cout<<"__________";
                		}
                		cout<<endl<<endl;
                		cout<<"DD/MM/YY    ";
                		for(k=1;k<n+1;k++)
                		{
                		cout<<"p"<<k<<"    ";
                		}
                		cout<<endl<<endl;
                		cout<<date<<"/"<<month<<"/"<<year<<"   ";
                		for(k=1;k<n+1;k++)
                		{
                			if(z[k]==1)
                			{
                				cout<<"P"<<"     ";
                			}
                			else
                			{
                				cout<<"A"<<"     ";
                			}
                		}
                		cout<<endl<<endl;
                		for(k=1;k<n+1;k++)
                		{
                			cout<<"__________";
                		}
                		cout<<endl;
                		cout<<endl;
                		break;
						default://To exit 
				exit(0);
            	}
                cout<<">>ENTER 1 TO TO UPDATE ANOTHER DAY ELSE 0  :";
                cin>>i;
                cout<<endl;
        }

}
void attend::calculate()//calculate the percentage
{
         int x,r;
         float s;
        x=(t*75)/100;
        s=(p*100)/t;
        if(s<75&&s>65)
        {
        		cout<<"   _________________________________________________________________________"<<endl<<endl;
                cout<<"                           YOUR ATTENDANCE IS LOW : "<<s<<"%"<<endl<<endl;
                r=x-p;
                cout<<"   ........................................................................."<<endl<<endl;
                cout<<"                        you must have attended"<<r<<"classes                "<<endl<<endl;
                cout<<"   _________________________________________________________________________"<<endl<<endl;
        }
         if(s<65)
        {
                int y;
                y=(t*65)/100;
                int  k=y-p;
                cout<<"   __________________________________________________________________________"<<endl<<endl;
                cout<<"                     YOUR ATTENDANCE IS : "<<s<<"%"<<endl<<endl;
                cout<<"   .........................................................................."<<endl<<endl;
                cout<<"                   you must have attended"<<k<<"classes                      "<<endl;
                cout<<"   __________________________________________________________________________"<<endl<<endl;
        }
        if(s>75)
        {
        		cout<<"   __________________________________________________________________________"<<endl<<endl;
                cout<<"                      YOUR ATTENDANCE IS :"<<s<<"%"<<endl<<endl;
                cout<<"   .........................................................................."<<endl<<endl;
            
                cout<<"   __________________________________________________________________________"<<endl<<endl;
        }
}



int main()
{
        attend o1,o2,o3;
        int a,w;
        ifstream file1;
        ofstream file2;
        cout<<endl;
        cout<<"                     STUDENT ATTENDANCE MAINTAINANCE SYSTEM                "<<endl;
        cout<<"                   ------------------------------------------              "<<endl<<endl;
        cout<<":::::::::::::::::::      ENTER ANY KEY TO SELECT OPTIONS     :::::::::::::::::::"<<endl;
        cin>>a;
        cout<<endl;
        while(a)
        {
        	cout<<"********************************   OPTIONS   **********************************"<<endl<<endl;//printing options
        	cout<<"                            1.VIEW YOUR ATTENDANCE"<<endl<<endl<<"                           2.UPDATE YOUR ATTENDANCE"<<endl<<endl;
        	cout<<"*******************************************************************************"<<endl;
        	cin>>w;
        switch(w)//perform options
        {
        	case 1:
        		file1.open("attendance1.txt");
        		file1.read((char *)& o1, sizeof(o1));
        		o1.calculate();
        		file1.close();
        		break;
        	case 2:
				file1.open("attendance1.txt");
				file1.read((char *)& o2, sizeof(o2));
				file1.close();
				o2.enter();
				file2.open("attendance1.txt");
				file2.write((char *)& o2, sizeof(o2));
				file2.close();
				break;

	// added missing part	
		default:
			;
		}
	}

return 0;
}


What I have tried:

I need to make a simple attendance management system in c. please anyone help
Posted
Updated 30-Apr-21 21:46pm
v3
Comments
Richard MacCutchan 27-Mar-21 4:03am    
How about you actually try to write the program yourself?
Rick York 27-Mar-21 14:56pm    
Yes. Anyone can. Even you.

That is really weak code though. The class has single letter member names and that is ridiculous, to put it nicely.

This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.

And frankly, finding something in a random language that you think you can hand in as your own work if somebody converts it for you is a very poor idea ...
 
Share this answer
 
Comments
ABHINAV Mohan 28-Mar-21 5:27am    
Yeah but can u show an example of a simple student attendance management system in c.just to get an idea.please
OriginalGriff 28-Mar-21 5:41am    
No, because that's pointless - you learn nothing from the exercise, not even "how to plagiarize homework".

Give it a try for yourself: you learn by doing, and that's why you have these exercises as homework ...
When you want to do it you must understand the differences between C++ and C and rework the code. So has C no classes, but structs and you must replace class functions with pure C code.

Best is to visit some C tutorial to find the correct solutions like for file and I/O.

tip: using pointers is helping to make code smarter, but you must understand it and avoid memory leaks.
 
Share this answer
 
As the previous speakers said, there are usually no complete solutions here, but help where it makes sense. The original C ++ code is very bad.There are many questionable places and without a description you would have to do reverse engineering here in order to port it useful. Most of it is rather easy to port. There are also places where the C ++ features are missing and you would have to make some effort. Here's a little help to get you started.

C
//#include<iostream>
//#include<fstream>
#include <stdio.h>
#include <stdlib.h>

// using namespace std;

typedef struct {
	float p,t;
} attend;

void enter(attend *at);
void calculate(attend *at);

int readdate(int* date, int* month, int* year)
{
	// todo
	return 1;
}

int main()
{
	attend o1;
	...

return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900