Saturday, February 8, 2014

PROGRAMME TO INITIALISE THE FIRST LETTER CAPITAL AFTER EVERY SPACE

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main()
{
clrscr();
char str[80];
cout<<"Enter any string"<<endl;
gets(str);
for(int i=0;str[i]!=NULL;i++)
{
if(str[i]==' ')
{
str[0]=toupper(str[0]);
str[i+1]=toupper(str[i+1]) ;
i++;
}
}
cout<<endl<<endl;
puts(str);
getch();
}

PROGRAMME TO COUNT NO OF DAYS YOU HAVE LIVED FROM YOUR BIRTHDAY TO PRESENT DATE

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int days=0,days1=0,days2=0,totaldays=0;
int main()
{
clrscr();
float d,m;
int y,a=0;
char month[10];
do
{
clrscr();
cout<<endl<<endl<<"================================================================================================================================================================";
cout<<endl<<endl<<endl<<'\t'<<'\t'<<'\t'<<"ENTER 1. to check how many days you have lived"<<endl;
cout<<endl<<endl<<'\t'<<'\t'<<'\t'<<"ENTER 2. to exit"<<endl<<endl<<endl;
cout<<"================================================================================================================================================================";
cout<<endl<<endl<<endl<<endl<<endl<<"ENTER CHOICE (1/2) : ";
cin>>a;
if(a==1)
{
clrscr();
cout<<endl<<endl<<"Enter BIRTHDATE   : ";
cin>>d;
if(d>31)
{
cout<<endl<<endl<<"INVALID DATE";
getch();
exit(0);
}
cout<<endl<<"ENTER BIRTH MONTH : ";
cin>>m;
if(m==1)
strcpy(month,"JANUARY");
else if(m==2)
strcpy(month,"FEBRUARY");
else if(m==3)
strcpy(month,"MARCH");
else if(m==4)
strcpy(month,"APRIL");
else if(m==5)
strcpy(month,"MAY");
else if(m==6)
strcpy(month,"JUNE");
else if(m==7)
strcpy(month,"JULY");
else if(m==8)
strcpy(month,"AUGUST");
else if(m==9)
strcpy(month,"SEPTEMBER");
else if(m==10)
strcpy(month,"OCTOBER");
else if(m==11)
strcpy(month,"NOVEMBER");
else if(m==12)
strcpy(month,"DECEMBER");
else
{
cout<<endl<<endl<<"INVALID MONTH"<<endl;
getch();
exit(0);
}

cout<<endl<<"ENTER BIRTH YEAR  : ";
cin>>y;
if(d>29&&m==2&&y%4==0)
{
cout<<endl<<endl<<"INVALID BIRTHDATE"<<endl;
cout<<endl<<endl<<"DATE EXCEEDS 29 and AS IT IS LEAP YEAR"<<endl;
getch();
exit(0);
}
else if(d>28&&m==2&&y%4!=0)
{
cout<<endl<<endl<<"INVALID BIRTHDATE"<<endl;
cout<<endl<<endl<<"DATE EXCEEDS 28 and AS IT IS NOT A LEAP YEAR"<<endl;
getch();
exit(0);
}
/*****************************************************************************************
 *****************************************************************************************
PLACING THE POINTER AT THE END OF THE BIRTH YEAR
 *****************************************************************************************
 ***************************************************************************************** */
if(m==1&&y%4==0)
days=366-d;
else
days=365-d;
if(strcmp(month,"FEBRUARY")==0&&y%4==0)
days=366-31-d;
else if(m==2)
days=365-31-d;
else if(m==3&&y%4==0)
days=366-31-29-d;
else if(m==3)
days=365-31-28-d;
else if(m==4&&y%4==0)
days=366-31-29-31-d;
else if(m==4)
days=365-31-28-31-d;
else if(m==5&&y%4==0)
days=366-31-29-31-30-d;
else if(m==5)
days=365-31-28-31-30-d;
else if(m==6&&y%4==0)
days=366-31-29-31-30-31-d;
else if(m==6)
days=365-31-28-31-30-31-d;
else if(m==7&&y%4==0)
days=366-31-29-31-30-31-30-d;
else if(m==7)
days=365-31-28-31-30-31-30-d;
else if(m==8&&y%4==0)
days=366-31-29-31-30-31-30-31-d;
else if(m==8)
days=365-31-28-31-30-31-30-31-d;
else if(m==9&&y%4==0)
days=366-31-29-31-30-31-30-31-31-d;
else if(m==9)
days=365-31-28-31-30-31-30-31-31-d;
else if(m==10&&y%4==0)
days=366-31-29-31-30-31-30-31-31-30-d;
else if(m==10)
days=365-31-28-31-30-31-30-31-31-30-d;
else if(m==11&y%4==0)
days=366-31-29-31-30-31-30-31-31-30-31-d;
else if(m==11)
days=365-31-28-31-30-31-30-31-31-30-31-d;
else if(m==12&&y%4==0)
days=366-31-29-31-30-31-30-31-31-30-31-30-d;
else if(m==12)
days=365-31-28-31-30-31-30-31-31-30-31-30-d;
cout<<endl<<endl<<"YOUR BIRTHDAY : "<<d<<"/"<<month<<"/"<<y;
cout<<endl<<endl;
float dd,mm;
int yy;
char month1[10];
cout<<endl<<endl<<"Enter TODAY'S DATE   : ";
cin>>dd;
if(dd>31)
{
cout<<endl<<endl<<"INVALID DATE";
getch();
exit(0);
}
cout<<endl<<"ENTER MONTH          : ";
cin>>mm;
if(mm==1)
strcpy(month1,"JANUARY");
else if(mm==2)
strcpy(month1,"FEBRUARY");
else if(mm==3)
strcpy(month1,"MARCH");
else if(mm==4)
strcpy(month1,"APRIL");
else if(mm==5)
strcpy(month1,"MAY");
else if(mm==6)
strcpy(month1,"JUNE");
else if(mm==7)
strcpy(month1,"JULY");
else if(mm==8)
strcpy(month1,"AUGUST");
else if(mm==9)
strcpy(month1,"SEPTEMBER");
else if(mm==10)
strcpy(month1,"OCTOBER");
else if(mm==11)
strcpy(month1,"NOVEMBER");
else if(mm==12)
strcpy(month1,"DECEMBER");
else
{
cout<<endl<<endl<<"INVALID MONTH"<<endl;
getch();
exit(0);
}

cout<<endl<<"ENTER YEAR           : ";
cin>>yy;
if(dd>29&&mm==2&&yy%4==0)
{
cout<<endl<<endl<<"INVALID DATE"<<endl;
cout<<endl<<endl<<"DATE EXCEEDS 29 and AS IT IS LEAP YEAR"<<endl;
getch();
exit(0);
}
else if(dd>28&&mm==2&&yy%4!=0)
{
cout<<endl<<endl<<"INVALID DATE"<<endl;
cout<<endl<<endl<<"DATE EXCEEDS 28 and AS IT IS NOT A LEAP YEAR"<<endl;
getch();
exit(0);
}
if(mm==1&&yy%4==0)
days1=dd;
else
days1=dd;
if(strcmp(month1,"FEBRUARY")==0&&yy%4==0)
days1=31+dd;
else if(mm==2)
days1=31+dd;
else if(mm==3&&yy%4==0)
days1=31+29+dd;
else if(mm==3)
days1=31+28+dd;
else if(mm==4&&yy%4==0)
days1=31+29+31+dd;
else if(mm==4)
days1=31+28+31+dd;
else if(mm==5&&yy%4==0)
days1=31+29+31+30+dd;
else if(mm==5)
days1=31+28+31+30+dd;
else if(mm==6&&yy%4==0)
days1=31+29+31+30+31+dd;
else if(mm==6)
days1=31+28+31+30+31+dd;
else if(mm==7&&yy%4==0)
days1=31+29+31+30+31+30+dd;
else if(mm==7)
days1=31+28+31+30+31+30+dd;
else if(mm==8&&yy%4==0)
days1=31+29+31+30+31+30+31+dd;
else if(mm==8)
days1=31+28+31+30+31+30+31+dd;
else if(mm==9&&yy%4==0)
days1=31+29+31+30+31+30+31+31+dd;
else if(mm==9)
days1=31+28+31+30+31+30+31+31+dd;
else if(mm==10&&yy%4==0)
days1=31+29+31+30+31+30+31+31+30+dd;
else if(mm==10)
days1=31+28+31+30+31+30+31+31+30+dd;
else if(mm==11&yy%4==0)
days1=31+29+31+30+31+30+31+31+30+31+dd;
else if(mm==11)
days1=31+28+31+30+31+30+31+31+30+31+dd;
else if(mm==12&&yy%4==0)
days1=31+29+31+30+31+30+31+31+30+31+30+dd;
else if(mm==12)
days1=31+28+31+30+31+30+31+31+30+31+30+dd;
cout<<endl<<endl<<"TODAY's DATE         : "<<dd<<"/"<<month1<<"/"<<yy<<endl;
/*****************************************************************************
 *****************************************************************************
to check no of leap years
 *****************************************************************************
 *****************************************************************************/
int noofyears=((yy-1)-(y));
int leap;
if(noofyears%4==0)
leap=noofyears/4;
else if(noofyears%4!=0)
leap=noofyears/4+1;
days2=leap+(365*noofyears);
cout<<endl<<endl<<endl<<endl<<"YOUR AGE                  : "<<noofyears;
cout<<endl<<endl<<"NO OF LEAP YEARS          : "<<leap;
totaldays=days+days2+days1;
cout<<endl<<endl<<"TOTAL DAYS YOU HAVE LIVED : "<<totaldays;
getch();
}
else if(a==2)
exit(0);
}while(a!=2);
}

Wednesday, February 5, 2014

A project on student reportcard c++

#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
class reportcard
{
float sno,percentage,rollno,p_marks,c_marks,m_marks,e_marks,co_marks;
char name[20],grade;
void cal();
public :
void getdetails();
void showdetails();
void tabular();
int retroll();
};
void reportcard::getdetails()         //funtion gets details
{
cout<<endl<<endl<<endl<<"Enter S.NO         : ";
cin>>sno;
cout<<endl<<endl      <<"Enter STUDENT NAME : ";
gets(name);
cout<<endl<<endl      <<"Enter ROLL NO      : ";
cin>>rollno;
cout<<endl<<endl<<endl<<endl<<"Enter Marks in PHYSICS (out of 100)   : ";
cin>>p_marks;
cout<<endl<<endl<<"Enter Marks in CHEMISTRY (out of 100) : ";
cin>>c_marks;
cout<<endl<<endl<<"Enter Marks in MATHS (out of 100)     : ";
cin>>m_marks;
cout<<endl<<endl<<"Enter Marks in ENGLISH (out of 100)   : ";
cin>>e_marks;
cout<<endl<<endl<<"Enter Marks in COMPUTER (out of 100)  : ";
cin>>co_marks;
cal();
}
void reportcard::showdetails()  //function show details
{clrscr();
cout<<endl<<endl<<endl<<"S.NO         : "<<sno;
cout<<endl<<endl      <<"STUDENT NAME : ";
puts(name);
cout<<endl<<endl      <<"ROLL NO      : "<<rollno;
cout<<endl<<endl<<endl<<endl<<"Marks in PHYSICS (out of 100)   : "<<p_marks;
cout<<endl<<endl<<"Marks in CHEMISTRY (out of 100) : "<<c_marks;
cout<<endl<<endl<<"Marks in MATHS (out of 100)     : "<<m_marks;
cout<<endl<<endl<<"Marks in ENGLISH (out of 100)   : "<<e_marks;
cout<<endl<<endl<<"Marks in COMPUTER (out of 100)  : "<<co_marks;
cout<<endl<<endl<<endl<<"PERCENTAGE : "<<percentage<<"%";
cout<<endl<<endl      <<"Grade      : "<<grade<<endl<<endl;
}
int reportcard::retroll()  //function returns roll number
{
return rollno;
}
void reportcard::cal()    //function calculates grade and percentage
{
percentage=(p_marks+c_marks+m_marks+e_marks+c_marks)/5;
if(percentage>=90)
grade='A';
else if(percentage<90&&percentage>=80)
grade='B';
else if(percentage<80&&percentage>=70)
grade='C';
else if(percentage<70&&percentage>=60)
grade='D';
else if(percentage<60&&percentage>=33)
grade='E';
else if(percentage<33)
grade='F';
}
void reportcard::tabular()
{
cout<<endl<<sno<<'\t'<<rollno<<'\t'<<name<<'\t'<<p_marks<<'\t'<<c_marks<<'\t'<<m_marks<<'\t'<<e_marks<<'\t'<<co_marks<<setw(13)<<percentage<<endl<<endl;
}


void appendrecords();   //appends data in binary file
void displayallrecords();  //shows all records in tabular form
void modifyrecord(int);  // modifies a record
void deleterecord(int);  //delets a record
void displayrecord(int); //displays a particular record
int main()
{
clrscr();
int num=0,a=0,b=0;
do
{
clrscr();
cout<<endl<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<'\t'<<'\t'<<'\t'<<"Press 1 to enter input/edit record menu"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 2 to show class result"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 3 to exit"<<endl<<endl;
cout<<endl<<endl<<endl<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<endl<<endl<<"ENTER CHOICE (1/2/3) : ";
cin>>a;
if(a==1)
{
clrscr();
cout<<endl<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<endl<<'\t'<<'\t'<<'\t'<<"Press 1 to input a new record"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 2 to display a particular record"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 3 to modify a record"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 4 to delete a record"<<endl<<endl;
cout<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<endl<<endl<<"ENTER CHOICE : ";
cin>>b;
if(b==1)
appendrecords();
else if(b==2)
{clrscr();
cout<<endl<<endl<<"ENTER ROLL NUMBER : ";
cin>>num;
displayrecord(num);
}
else if(b==3)
{clrscr();
cout<<endl<<endl<<"ENTER ROLL NUMBER : ";
cin>>num;
modifyrecord(num);
}
else if(b==4)
{
clrscr();
cout<<endl<<endl<<"ENTER ROLL NUMBER : ";
cin>>num;
deleterecord(num);
}
else
{
cout<<endl<<endl<<endl<<"WRONG CHOICE, Press any key to return back...";
getch();
}
}
else if(a==2)
displayallrecords();
else if(a==3)
exit(0);
else
{
cout<<endl<<endl<<endl<<"WRONG CHOICE, Press any key to enter again....";
getch();
}
}while(a!=3);
return 0;
}
void appendrecords()//appending record into binary file
{
clrscr();
reportcard ob;
ofstream fo;
fo.open("file.dat",ios::binary|ios::app);
ob.getdetails();
fo.write((char*)&ob,sizeof(ob));
fo.close();
cout<<endl<<endl<<"RECORD INPUTED"<<endl;
getch();
}

void displayrecord(int n) // reads a particular record from file
{
clrscr();
reportcard ob;
ifstream fin;
fin.open("file.dat",ios::binary);
while(fin.read((char*)&ob,sizeof(reportcard)))
{
if(ob.retroll()==n)
{
clrscr();
cout<<endl<<endl;
ob.showdetails();
}
}
fin.close();
getch();
}
void modifyrecord(int n)
{
clrscr();
reportcard ob;
fstream fin;
fin.open("file.dat",ios::binary|ios::in|ios::out);
if(!fin)
{
cout<<"File Doesnt Exist"<<endl;
return;
}
while(fin.read((char*)&ob,sizeof(reportcard)))
{
if(ob.retroll()==n)
{
clrscr();
ob.showdetails();
cout<<endl<<endl<<"ENTER NEW DETAILS"<<endl;
ob.getdetails();
int pos=(-1)*sizeof(ob);
fin.seekg(pos,ios::cur);
fin.write((char*)&ob,sizeof(reportcard));
cout<<endl<<endl<<"RECORD UPDATED"<<endl;
}
}
fin.close();
getch();
}
void deleterecord(int n)
{
clrscr();
reportcard ob;
ifstream fin;
fin.open("file.dat",ios::binary);
ofstream fo;
if(!fin)
{
cout<<"FILE DOESNT EXIST"<<endl;
return;
}
fo.open("temp.dat",ios::binary|ios::out);
fin.seekg(0,ios::beg);
while(fin.read((char*)&ob,sizeof(reportcard)))
{
if(ob.retroll()!=n)
{
fo.write((char*)&ob,sizeof(reportcard));
}
}
fin.close();
fo.close();
remove("file.dat");
rename("temp.dat","file.dat");
cout<<endl<<endl<<"RECORD DELETED"<<endl;
getch();
}
void displayallrecords()
{
clrscr();
reportcard ob;
ifstream fin;
fin.open("file.dat",ios::binary);
cout<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<"S.NO"<<'\t'<<"ROLLNO"<<'\t'<<"NAME"<<setw(15)<<"PHY"<<'\t'<<"CHEM"<<'\t'<<"Maths"<<'\t'<<"Eng"<<'\t'<<"Comp"<<'\t'<<"Per"<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
while(fin.read((char*)&ob,sizeof(ob)))
{
ob.tabular();
}
fin.close();
getch();
}