Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<fstream>
#include<string>
#include<ctime>
#include<conio.h>
 using namespace std;
class tt{
	public:
   	string presenttime()
      	{
   time_t now = time(0);
   char* dt = ctime(&now);
 	string d=(string)dt;
    	return d;
      	}
 };
 class form
 {
  public:
	void display(string s)
 	{
    	system("cls");
   	string line;
     	cout<<"\n"<<endl;
   	
   	fstream my(s.c_str());
 int i=0;
    	while(getline(my,line))
    	{ 
      	cout<<line<<endl;
   i++;
  if(i>=15){
  i=0;
  cin.ignore();
   }
    	}
  	my.close();
  	}
 	};
class feedback
 {
  public:
     	void feedtake(string t)
    {
   
   string s;
	ofstream my("feedback",ios::app);
       	cout<<"enter ur feedback"<<endl<<"\t";
 	cin.ignore();
        getline(cin,s);
          	tt g;   string p=g.presenttime();
              	cout<<"please enter a rating for the application[0-5] : ";
              	string x;  cin>>x;	rating(x);
		my<<endl<<"->"<<"  "<<t<<endl<<"	Rating :   "<<x<<endl<<"  "<<"  Feedback : "<<s<<endl<<"AT : "<<p<<"\n"<<endl;
              	my.close();
             	
  }
     	void maintype(string r)
    {
   
                    	
              	float y=calrating();
             	cout<<fixed<<"The average rating is : "<<y<<endl;
	cout<<"\n\n\t\t1.GIVE A FEEDBACK\n\n"<<endl;
	cout<<"\t\t2.VIEW FEEDBACK\n\n"<<endl;
     cout<<"\t\tENTER YOUR OPTION : ";
             	int x; 
  cin>>x;
            	switch(x)
               	{
   case 1:{
 	cout<<"PLEASE ENTER UR FEEDBACK"<<endl<<"->";
  	feedtake(r);
    }
    break;
   case 2: {
     form s;
  	
                  	s.display("feedback");
    }
     break;
               	}
             	
  }
	
 int fiee()
   {
	string s;
     int i=0;
	ifstream my("ratings");
 	while(getline(my,s))
      {
 
    	i++;
	  } 
 	return i;
   }
    	int calrating()
 {
   int x=fiee(); 
	int a[x];
   int  i=0;
     fstream my("ratings");
	string line;
  while(getline(my,line))
 	{
       	a[i]=stioc(line);
        	i++;
       	if(i==x)
           	break;
 	}
    	  my.close();
          	int b=0;
   	for(int i=0;i<x;i++)
      	{ 
          	b+=a[i];
    	}
         	return (b/x);
 }
	int stioc(string s)
  {
  	 int n=0;
	 for(int i=0;i<s.length();i++)
	   {
     	n+=(int)(s[i]-'0');
     	n*=10;
  	   }
   	return n/10;
 }
	void userinfo(string s)
    	{
	ofstream yy("userdetails",ios::app);
     yy<<s<<endl;
  yy.close();
 }
   	void rating(string s)
    	{ 
	ofstream xx("ratings",ios::app);
  	xx<<s<<endl;
       	xx.close();
    	}
 };
 class administrator
 {
  public:
	int admin(string b,string a)
   	{
	ifstream my(b.c_str());
  	string line;
	while(getline(my,line))
  	{
     	if(a==line)
       	return 1;
     	
   	}
    	return 0; 
 	}
 	string password()
  	{
	
  	 char ch[100],c;
   	int i=0;
 	  while((c=_getch())!=13)
  	{
	  ch[i]=c;  i++;  cout<<"*";
	  
 	} 
  	return ch;
   }
	int  maintype()
 	{
 	  cout<<"\n\n\n\n\n";
   cout<<"\t\t\tENTER  THE ROOT USER NAME : ";
      	string r;   cin>>r;
     	int c=admin("rootusers",r);
    	cout<<"\n\t\t\t"<<"   	ENTER THE PASSWORD : ";
       	string k;  k=password();
      	int f=admin("passwords",k);
    	if(c==1&&f==1)
        	{
          	system("cls");
          	cout<<"\n\n\n\n\n\n\n\t\t\t\t\t1.VIEW LAST LOGS";
    	cout<<"\n\n\n\t\t\t\t\t2.CREATE A NEW SUPER USER";
   	cout<<"\n\n\n\t\t\t\t\t\tEnter Your Option : ";
   	int m;
   	cin>>m;
    	switch(m)
     	{
     	 case 1 :{
             	form i;
                      	i.display("userdetails");   	  
    	}
     	break;
     case 2: {
     	passw:
   	system("cls");
      cout<<"\n\n\t\t\tEnter the User name : ";
   	string g,x,y;
    	cin>>g;
      	cout<<"\n\n\t\t\tEnter the Password : ";
       	x=password();
      	cout<<"\n\n\t\t\tReenter the password : ";
   	y=password();
   	int k=1;
    	if(x==y&&k!=admin("rootusers",g))
     	{
     	 rootname("rootuser",g);
     	 rootname("passwords",x);
     	 cout<<"\n\n\n\t\t\tROOT USER ADDED";
     	}
     	else
      	{
      	 cout<<"Password Don't Match || PLEASE TRY AGAIN"<<endl;
        goto passw;
       }
     }
  	break;
 	}
             	return 1;
 	}
 	else return 0;
    	
 	}
 	void rootname(string q,string s)
    	{
	ofstream yy(q.c_str(),ios::app);
     yy<<s<<endl;
    yy.close();
 }
  };
 class inter
  {
 public:
      	
     	string maintype()
     	{
     	 
     cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t";
              	cout<<"ENTER YOUR NAME OR ROLL NO."<<endl;
       	  cout<<"\n\n\t\t\t\t\t\t\t\t\t1.Roll No."<<endl<<"\n\t\t\t\t\t\t\t\t\t2.Name"<<endl;
	  cout<<"\n\t\t\t\t\t\t\tChoose a option  : ";
  	   int h;   cin>>h;
   string g;
             	if(h==1)
               	{
                 	cout<<"\n\t\t\t\t\t"<<"  	"<<"Please Enter Your Roll no. : ";
                  	cin>>g;
                  	g="Roll NO. : "+g; }
              	else if(h==2)
                 	{
                 	cout<<"\n\t\t\t\t\t\t\tPlease Enter Your Name : ";
                  	cin>>g;
                 	g="Name : "+g;  }
              	tt c;  string z=c.presenttime();
          	user(g,z);
          	return g;
  }
   	
             	
     	void user(string s,string z)
   	{
    	ofstream xx("userdetails",ios::app);
    	xx<<s<<endl<<" LOGIN TIME : "<<z<<endl;
    	xx.close();
   	}
  };
int  main()
  {
	system("cls");
	inter j;
	string s=j.maintype();
	form a;  
 jump:
	system("cls");
	
	char ch='y';
 while(ch=='y'||ch=='Y')
 {
  cout<<"\n\n\n\t\t\t\t\t\t\t"<<"WELCOME TO MODERN WORLD"<<endl;
  cout<<"\n\n\n"<<endl;
  cout<<"\t\t\t\t\t1.DISLPLAY THE PERIODIC TABLE\n\n"<<endl;
  cout<<"\t\t\t\t\t2.SEARCH FOR A PERIODIC ELEMENT\n\n"<<endl;
  cout<<"\t\t\t\t\t3.HISTORY OF MODERN PERIODIC TABLE\n\n"<<endl;
  cout<<"\t\t\t\t\t4.OTHERS\n\n"<<endl;
   cout<<"\t\t\t\t\t5.EXIT\n\n"<<endl;
 	
  cout<<"\t\t\t\t ENTER YOUR CHOICE: ";
 int n;  cin>>n;
 system("cls");
  switch(n)
   {
 	case 1: a.display("structure");
         	break;
 	case 2: {
          	char key='y';
          	while(key=='y'||key=='y')
          	{ system("cls"); 
             	cout<<"\n\n\n\n\n\n\t\t\tEnter the ATOMIC No./SYMBOL/NAME of the element : ";
            	string q;  
 cin>>q;
             	ifstream xx(q.c_str());
                	if(xx)
                  	{
     a.display(q);
                           	
   }
                 	else
                   	{
	if(((int)q[0])>=65&&((int)q[0])<97)
 	{
	   q[0]=(char)(((int)q[0])+32);
 	}
	   q=(string)q;
            	a.display(q);
             	}
     cout<<"\n\n\nDo you want to continue searching[Y/y] : ";  cin>>key;
        	}
           	
         	}
        	break;
 	case 3:a.display("history");
        	break;
	case 4:
 	{
           	upp:
           		char c=_getch();
           	 system("cls");
  cout<<"\n\n\t\t\t1.ADMINISTRATOR"<<endl;
      	
  cout<<"\n\n\t\t\t2.FEEDBACK"<<endl;
  cout<<"\n\n\t\t\t3.DEVELOPER DETAILS"<<endl;
  cout<<"\n\n\t\t\t4.ABOUT"<<endl;
  cout<<"\n\n\t\t\t5.RETRUN TO MAIN MENU"<<endl;
   cout<<"\n\n\t\t\t6.EXIT\n\n"<<endl;
           	cout<<"\n\t\tEnter your choice : ";
           	int v; cin>>v;
        	system("cls");
        	switch(v)
       	{
          	case 1:
             	{
                 	administrator v;
                 	system("cls");
                 	int h=v.maintype();
  	if(h==0)
   	cout<<"\n\n\n\tENTER A VALID USERNAME OR PASSWORD";
     	char o=_getch();
            	}
             	break;
          	case 2:{
        	 feedback f;
                	f.maintype(s);
                  	char o=_getch();
                	 }
      	 break;	
    	 case 3 : {
            	system("cls");
      	a.display("details");
      	char o=_getch();   }
          	   break;
   	case 5 :{ goto jump; }
           	break;
   	case 6 :{
                     	
                     	exit(0);
                      	}
                      	break;
      	case 4 : {
                	form g; g.display("about");  
	}
              	break;
  	
     	default : cout<<"ENTER A VALID OPTION"<<endl;
    	}
      	goto upp;   	
    	}  
     	case 5 :{
              	exit(0); 
              	}
   break;  	
   default: cout<<"enter a valid option : ";
         	break;
   }
cout<<"\n\n\nDo u want to Return to main menu[Y/y] : ";
   	
 	cin>>ch;
	system("cls");
 	
  }
 return 0;
 }


What I have tried:

I have replaced _getch with getchar and added files like h.txt in the same directory as the cpp file.
Posted
Updated 14-Mar-21 5:26am
v2

1 solution

You are trying to run cls command (to clear the screen) on the console using the system(). cls command only exists on DOS or command prompt on Windows.
C++
system("cls");
If your program is running on Bash on Linux or MacOSX, you can try clear.
C++
system("clear");
 
Share this answer
 
Comments
CPallini 14-Mar-21 11:27am    
5.

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