Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  student
Language: C/C++
Code:

     //writen by reza teimourzadeh
#include <iostream>
#include <string.h>
#include <sstream>
#include <math.h>
#include <fstream>
#include <cstdlib>
#include <cctype>
#include <time.h>
using namespace std;
//globall variable
ofstream dfile("c:\\text-d.txt",ios::in|ios::out|ios::app);
ifstream hfile("c:\\text-d.txt",ios::in|ios::out|ios::app);
ofstream file("c:\\text.txt",ios::in|ios::out|ios::app);
ifstream mfile("c:\\text.txt",ios::in|ios::out|ios::app);
float number [130];
string name [130];
string family [130];
int i,x;
int sno[130];
struct tm * ptm;
class taghvim
{public:
void ctime()
{int day,month,count;
time_t rawtime;
struct tm * ptm;
time(&rawtime);
ptm=localtime(&rawtime);

day=ptm->tm_yday-78;
if(day<=0)
day=day+365;
month=day/31;
if(month>6)
month=6;
day -= month*31;
if(day !=0)
{count=day/30;
month += count +1;
day -=count *30;}
else
day=31;
if(day==0)
{day=30;
month--;}
int year=1398;
cout<<day<<"/"<<month<< "/"<<year<<"/";
switch(month)
{case 1:
cout<<"farvardin";
break;
case 2:
cout<<"ordibehesht";
break;
case 3:
cout<<"khordad";
break;
case 4:
cout<<"tir";
break;
case 5:
cout<<"mordad";
break;
case 6:
cout<<"shahrivar";
break;
case 7:
cout<<"mehr";
break;
case 8:
cout<<"aban";
break;
case 9:
cout<<"azar";
break;
case 10:
cout<<"dey";
break;
case 11:
cout<<"bahman";
break;
case 12:
cout<<"esfand";
break;}
int week=ptm->tm_wday;
cout<<"/";
switch(week)
{case 0:
cout<<"sun";
break;
case 1:
cout<<"mon";
break;
case 2:
cout<<"tue";
break;
case 3:
cout<<"wed";
break;
case 4:
cout<<"tur";
break;
case 5:
cout<<"fri";
break;
case 6:
cout<<"sat";
break;}
cout<<"__"<<ptm->tm_hour<<":"<<ptm->tm_min<<":"<<ptm->tm_sec;}};
class cmenu
{protected:
taghvim ta;
public:
void pmenu()
{
ta.ctime();
cout<<"\n---------menu---------"<<endl;
cout<<"----enter selection :----"<<endl;
cout<<" 1:enter information of student "<<endl;
cout<<" 2:search student "<<endl;
cout<<" 3:edit information of student "<<endl;
cout<<" 4:show student info "<<endl;
cout<<" 5:tools"<<endl;
cout<<" 6:-------exit--------"<<endl;
}};
class menu
{public:
void selectmenu(int d)
{cout<<"select mode of calculator "<<endl;
cout<<"1---operation + - * / ---"<<endl;
cout<<"2----advance mode---- "<<endl;
cout<<"3----return menu----"<<endl;}};
class Calculator
{
public:
double Ccalculate(double k, char oper, double h);
double Calculate(double k, char oper, double result);
double calc(char op[ ] ,double f);
};
double Calculator::Ccalculate(double k, char oper, double h)
{
    switch(oper)
    {
        case '+':
            return k + h;
        case '-':
            return k - h;
        case '*':
            return k * h;
        case '/':
            return k / h;
        default:
            return 0;
    }
}
double Calculator::Calculate(double k, char oper, double result)
{
    switch(oper)
    {
        case '+':
 return result+=k ;
        case '-':
return result-=k ;
        case '*':
return result*=k ;
        case '/':
return result/=k ;
        default:
            return 0;
    }}

double Calculator::calc(char op[ ],double f)
{
double r;
cout<<"enter function and number (like : sin 0.5 : sqrt 16 : log 20) :"<<endl;
cin >>op >>f;
if (strcmp(op,"sin")==0)r=sin(f);
else if(strcmp(op,"cos")==0)r=cos(f);
else if(strcmp(op,"tan")==0)r=tan(f);
else if(strcmp(op,"exp")==0)r=exp(f);
else if(strcmp(op,"sqrt")==0)r=sqrt(f);
else if(strcmp(op,"log10")==0)r=log10(f);
else if(strcmp(op,"log")==0)r=log(f);
else if(strcmp(op,"ceil")==0)r=ceil(f);
else if(strcmp(op,"floor")==0)r=floor(f);
else r=0;
cout << op <<"("<<f<<")="<<r<<endl;
return(r);} 
class menu1
{public:
void cmenu()
{cout<<"1-convert meter "<<endl;
cout<<"2-convert centimeter"<<endl;
cout<<"3-convert fahrenheit "<<endl;
cout<<"4-convert celsius  "<<endl;
cout<<"5-convert kilo "<<endl;
cout<<"6-convert area "<<endl;
cout<<"7-convert bulk "<<endl;
cout<<"8--return menu--"<<endl;}};
class convert 
{public:
double convertmeter(double meter,double cm,double feet,double inch,double yard,double mile)
{cm=meter*100;
cout.precision(15);
cout<<meter<<" meter to cm is :"<<cm<<endl;
feet=meter*3.28;
cout<<meter<<" meter to feet is :"<<feet<<endl;
inch=meter*39.37;
cout<<meter<<" meter to inch is :"<<inch<<endl;
yard=meter*0.9144;
cout<<meter<<" meter to yard is :"<<yard<<endl;
mile=meter*0.00062137;
cout<<meter<<" meter to mile is :"<<mile<<endl;}
double convertcm(double meter,double cm,double feet,double inch,double yard)
{meter=cm/100;
cout<<cm<<" cm to meter is :"<< meter<<endl;
feet=cm/32.8;
cout<<cm<<" cm to feet is :"<<feet<<endl;
inch=cm/2.54;
cout<<cm<<" cm to inch is :"<<inch<<endl;
yard=cm/91.44;
cout<<cm<<" cm to yard is :"<<yard<<endl;}
double convertfahren(double fahrenheit,double celsius,double kelvin)
{celsius=(fahrenheit-32)/1.8;
cout<<fahrenheit<<" fahrenheit to celsius is :"<<celsius<<endl;
kelvin=fahrenheit-459.67;
cout<<fahrenheit<<" fahrenheit to kelvin is :"<<kelvin<<endl;}
double convertcelsius(double fahrenheit,double celsius,double kelvin)
{fahrenheit=(celsius*1.8)+32;
cout<<celsius<<" celsius to fahrenheit is :"<<fahrenheit<<endl;
kelvin=celsius+273.15;
cout<<celsius<<" celsius to kelvin is :"<<kelvin<<endl;}
double convertkilu(double kilo,double gram)
{gram=kilo*1000;
cout.precision(15);
cout<<kilo<<"  kilo to gram is : "<<gram<<endl;}
double convertpound(double kilo,double pounds)
{pounds=kilo*2.2046;
cout<<kilo<<" kilo to pounds is :"<<pounds<<endl;}
double convertarea(double area,double meter2,double cm,double feet,double inch,double yard,double mile)
{area =meter2* 10.764;
cout.precision(15);
cout<<meter2<<" m 2 equal to "<<area<<" feet 2"<<endl;
area=meter2*10000;
cout.precision(15);
cout<<meter2<<" m 2 equal to "<<area<<" cm 2"<<endl;
area=meter2*1550.0031;
cout.precision(15);
cout<<meter2<<" m 2 equal to "<<area<<" inch 2"<<endl;
area=meter2*1.19599;
cout.precision(15);
cout<<meter2<<" m 2 equal to "<<area<<" yard 2"<<endl;}
double convertbulk(double bulk,double meter3,double cm,double feet)
{bulk=meter3/0.000001;
cout.precision(15);
cout<<meter3<<" m 3 equal to "<<bulk<<" cm 3 "<<endl;
bulk=meter3*35;
cout<<meter3<<" m 3 equal to "<<bulk<<" feet 3"<<endl;
bulk=meter3*264.17218;
cout<<meter3<<" m 3 equal to "<<bulk<<" gal "<<endl;
bulk=meter3*1000;
cout.precision(15);
cout<<meter3<<" m 3 equal to "<<bulk<<" liters "<<endl;}};
class center
{protected:
//
public:
void entername(float number[ ],string name [ ],string family[ ],int x)
{{for(i=0;i<x;i++)

{cout<<" enter name and family and number of student with spacebar"<<i+1<<":"<<endl;
//getline(cin,name[i]);
cin>>name[i]>>family[i]>>number[i];
int day,month,count;
time_t rawtime;
struct tm * ptm;
time(&rawtime);
ptm=localtime(&rawtime);

day=ptm->tm_yday-78;
if(day<=0)
day=day+365;
month=day/31;
if(month>6)
month=6;
day -= month*31;
if(day !=0)
{count=day/30;
month += count +1;
day -=count *30;}
else
day=31;
if(day==0)
{day=30;
month--;}
int year=1398;
sno[i]=rand () %(99999999-10000000+1)+10000000;
dfile<<name[i]<<" "<<family[i]<<" "<<number[i]<<" "<<sno[i]<<"__"<<day<<"/"<<month<< "/"<<year<<"__"<<ptm->tm_hour<<":"<<ptm->tm_min<<":"<<ptm->tm_sec<<endl;
file<<name[i]<<" "<<family[i]<<" "<<number[i]<<" "<<sno[i]<<endl;}
file.flush();
//file.close();
}}};

class cshow : public center
{public:
void shownumber(float number [ ],string name[ ],string family[ ],int x)
{
for(i=0;i<x;i++)
{
cout<<" number of entered is "<<i+1<<" :"<<name[i]<<" "<<family[i]<<" "<<number [i]<<"serial number is  :"<<sno[i]<<endl;}}};
class csort :public center
{protected:
int j;
float temp;
public:
void sort(float number[ ],string name[ ],string family[ ],int x)
{
for(i=0;i<x-1;i++)
for(j=0;j<x-i-1;j++)
if(number[j]>number[j+1])
{temp=number[j];
number[j]=number[j+1];
number[j+1]=temp;}}};
class cshowsort : public center
{
public:
void shownumbersort(float number [ ],string name[ ],string family[ ],int x)
{
for(i=0;i<x;i++)
{cout<<" number of entered with sort is "<<i+1<<" :"<<name[i]<<" "<<family [i]<<" "<<number [i]<<endl;}}};

class cavreage : public center
{protected:
float sum;
float aavreage;
public:
void avreage(float number[ ],int x){for(i=0;i<x;i++)
{sum+=number[i];}
aavreage=sum/x;
cout.precision(4);
cout<<" avreage of student is :"<<aavreage<<endl;}};
class csearch:public center
{protected:
string ssearch;
public:
void search (float number[ ],string name[ ],string family[ ],int x)
{int j=1;
if(!mfile)
{cout<<" file not find"<<endl;}
ifstream mfile ("c:\\text.txt");
if (mfile.is_open())
{for(;;)
{mfile>>name[i]>>family[i]>>number[i]>>sno[i];
if(mfile.eof()) break;
cout<<j++<<"-"<<name[i]<<" "<<family[i]<<" "<<number[i]<<" "<<sno[i]<<endl;}}
cout<<" enter family of student to search :"<<endl;
cin>>ssearch;
{ifstream mfile ("c:\\text.txt");
if(!mfile)
{cout<<" file not find"<<endl;}

{while(!mfile.eof())
for(i=0;i<60;i++)
{mfile>>name[i]>>family[i]>>number[i]>>sno[i];
{
if (family[i]==ssearch)
{
cout <<" student " << name[i]<<" "<<family[i]<<"  "<<number[i]<<" "<<sno[i]<<" found at line "<<i+1<<endl;
return;

}}}
cout << " item "<<ssearch<<" not found."<<endl;}}}};
class cedit:public center
{
protected:
string eedit,n,fa;
float nu;
public:
void edit(float number[ ],string name[ ],string family[ ],int x)
{cout<<" enter family of student that you want edit :"<<endl;
cin>>eedit;

{if(!mfile)
{cout<<" file not find"<<endl;}
ifstream mfile ("c:\\text.txt");
if (mfile.is_open())
{for(;;)
{mfile>>name[i]>>family[i];
if(mfile.eof()) break;
for(i=0;i<60;i++)
{
if(family[i]==eedit)
{cout<<" enter name and family and number of student :"<<endl;
cout<<" enter name :"<<endl;
cin>>n;
cout<<" enter family :"<<endl;
cin>>fa;
cout<<" enter number :"<<endl;
cin>>nu;
cout<<" edit sucssesfull "<<endl;}
else
{cout<<" family not fond"<<endl;
break;}
if(family[i]==eedit)
{name[i]=n;
//file<<name[i];
family[i]=fa;
//file<<family[i];
number[i]=nu;

sno[i]=rand () %(99999999-10000000+1)+10000000;
file<<name[i]<<" "<<family[i]<<" "<<number[i]<<" "<<sno[i]<<endl;}}}}
file.close();
//strcpy(name[i],n);
//strcpy(family[i],f);
//strcpy(number[i],nu);
}}};
class cfile : public center
{public:
void studentinfo(float number[ ],string name[ ],string family[ ],int x)
{if(!hfile)
{cout<<" file not find"<<endl;}
string line;
ifstream hfile ("c:\\text-d.txt");
if (hfile.is_open())
{while(!hfile.eof())
{getline(hfile,line);
cout<<line<<endl;
}
hfile.close();
}
else 
cout<<"unable to open file";}};
class cavreageall
{public:
void avreageall (float number[ ],string name[ ],string family[ ],float sum,float allave)
{int j=0;
if(!mfile)
{cout<<" file not find"<<endl;}
ifstream mfile ("c:\\text.txt");
if (mfile.is_open())
{for(;;)
{mfile>>name[i]>>family[i]>>number[i]>>sno[i];
if(mfile.eof()) break;
cout<<(j++)+1<<"-"<<name[i]<<" "<<family[i]<<" "<<number[i]<<" "<<sno[i]<<endl;
sum+=number[i];}
allave=sum/j;
cout.precision(4);
cout<<"avreage of student is "<<allave<<endl;}}};
int main()
{if (!file)
{cout<<" file not find"<<endl;}
int x,y,t;
double k = 0;
    double h = 0;
    double result = 0;
    char oper = '*';
   char op[6];
double f;
int d,select;
double meter,meter2,meter3,cm,feet,inch,yard,mile,area,bulk,fahrenheit,celsius,kelvin,kilo,gram,pounds;

float number [130];
string name [130];
string family [130];
float sum;
float allave;
center ent;
cshow enr;
csort co;
cshowsort sh;
cavreage av;
csearch se;
cmenu me;
cedit ed;
cfile cf;
Calculator c;
menu m;
menu1 men;
convert cov;
cavreageall cav;
while(1)
{label1:
me.pmenu();
cin>>y;
switch (y)
{case 1:
cout<<" enter number of student:"<<endl;
cin>>x;
ent.entername(number,name,family,x);
enr.shownumber(number,name,family,x);
//co.sort(number,name,family,x);
sh.shownumbersort(number,name,family,x);
av.avreage(number,x);
break;
case 2:
se.search(number,name,family,x);
break;
case 3:
ed.edit(number,name,family,x);
break;
case 4:
cf.studentinfo(number,name,family,x);
cav.avreageall(number, name, family, sum,allave);
break;
case 5:
cout<<"1----calculator----"<<endl;
cout<<"2----convertor----"<<endl;
cin>>select;
switch(select)
{case 1:
label:
m.selectmenu(d);
cin>>d;
switch(d)
{case 1:
cout << "Calculator Console Application" << endl;   
    cout << "Please enter the operation to perform. Format: x+y | x-y| x*y | x/y"  << endl;
    cin >>k>>oper>>h;
result=c.Ccalculate(k,oper,h);
cout.precision(15);
cout<<k<<oper<<h<<"="<<result<<endl;
    while (true)
    {
        cin>>oper>>k;
cout<<result<<oper<<k;
result = c.Calculate(k, oper,result);
cout.precision(15);
        cout << "=" << result << endl;}
    
break;
case 2:
c.calc(op,f);
goto label;
case 3:
goto label1;
break;
}
case 2:
while(true)
{men.cmenu();
cout<<"enter number of select :"<<endl;
cin>>t;
switch(t)
{case 1:
cout<<"enter meter to convert :"<<endl;
cin>>meter;
cov.convertmeter(meter,cm,feet,inch,yard,mile);
break;
case 2:
cout<<"enter centimeter to convert :"<<endl;
cin>>cm;
cov.convertcm(meter,cm,feet,inch,yard);
break;
case 3:
cout<<"enter fahrenheit to convert :"<<endl;
cin>>fahrenheit;
cov.convertfahren(fahrenheit,celsius,kelvin);
break;
case 4:
cout<<"enter celsius to convert :"<<endl;
cin>>celsius;
cov.convertcelsius(fahrenheit,celsius,kelvin);
break;
case 5:
cout<<"enter kilo to convert :"<<endl;
cin>>kilo;
cov.convertkilu(kilo,gram);
cov.convertpound(kilo,pounds);
break;
case 6:
cout<<"enter area m 2 to convert :"<<endl;
cin>>meter2;
cov.convertarea(area,meter2,cm,inch,feet,yard,mile);
break;
case 7:
cout<<"enter bulk m 3 to convert :"<<endl;
cin>>meter3;
cov.convertbulk(bulk,meter3,cm,feet);
break;
case 8:
goto label1;
break;}}}
case 6:
exit(0);}}
cin.get();
 }          
Comments: