Is this good programming or bad?????

i wrote this cod to be the password interface to my first full program

i am so beginner in programing advice me please

is this good programing or bad ???

and if this bad programing What can i do?????

is there any books can i read to improve my coding ????

____________________________________________________________________________
/*
Regesteration pro
this program creats a new password
and
cheks a user number and poassword if they correct or not

this program created on
24/sep/2009 by MOTDCS....
*/


#include<iostream>
#include<fstream>
using namespace std;
class pass//password class
{

public:
pass()//constructor
{}
void addPW(double sNum,double sPW)//add new password function
{
fstream stu_sPass("studentPassW.txt",ios::app);//opens txt file to add data


stu_sPass<<sNum<<"\t\t"<<sPW<<endl;//add data to the file
stu_sPass.close();//close the file to save data


}

bool checkPW(double sNum,double sPW)//function to check password & number
{
double pass,num;//variables to save data from the file
fstream stu_rPass("studentPassW.txt");//to open file and read from
while(!stu_rPass.eof())//check if EOF file set
{
stu_rPass>>num;//saves the number to num var (the number is all character up to first white space)
stu_rPass>>pass;//saves the password to pass var (the pass is all character from that white space)
if((sNum==num&&sPW==pass))//checks if the pass&num are coreect
return true;
else
return false;
}
}



~pass()//destructor
{}

};

int main(void)
{
pass stuPass;//stuPass object from class pass
double sPW,sNum;//variables to manipulate data from main
int choice,check;//choice to manipulate the choices list,check to get check result from checkPW function
cout<<"To creat new password press 1 ...\nTo read password file press 2 ...."<<endl;
cin>>choice;
if(choice==1)
{
cout<<"Enter new number"<<endl;
cin>>sNum;
cout<<"Enter new sPW"<<endl;
cin>>sPW;
stuPass.addPW(sNum,sPW);
}
if(choice==2)
{
cout<<"Enter Your number"<<endl;
cin>>sNum;
cout<<"Enter your sPW"<<endl;
cin>>sPW;
check=stuPass.checkPW(sNum,sPW);
if(check==1)
cout<<"Welcome to my program"<<endl;
else
cout<<"Access denied"<<endl;
}

}


_________________________________________________
please help .....






How can you expect people to help you when your code is almost unreadable due to lack of code tags and indentation?

Without reading it properly, your main function doesn't return 0, you don't specify whether your fstream is input or output (or both) in pass::checkPW, and in main, although it would work, check should be bool seeing as it is assigned the value of what is returned by pass::checkPW.

Your constructor and destructor aren't doing anything so there's not much point in them being there. There's not much point to the class in general because all it has is its member functions which could really just be global functions. I would abandon the class.
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    bool checkPW(double sNum,double sPW)//function to check password & number 
    {
        double pass,num;//variables to save data from the file
        fstream stu_rPass("studentPassW.txt");//to open file and read from
        while(!stu_rPass.eof())//check if EOF file set
        {
            stu_rPass>>num;//saves the number to num var (the number is all character up to first white space)
            stu_rPass>>pass;//saves the password to pass var (the pass is all character from that white space)
            if((sNum==num&&sPW==pass))//checks if the pass&num are coreect
                return true;
            else
                return false;    // ?? do you really want to return here?
        }
        // Should have a return here!
    }
Last edited on
chewbob
I told you i just stated learning c++

so that now i am lost

because i know the basics of c and oop but i can not use them

_________
you mean this is bad programing
ok

help me to write a redable code please

can you give me references to start with

ex

when i must use class and when i must abandon class ?????

___________________
and thanks for your help in your comment i will take care of your notes...

___________________________________________________________________--
Grey Wolf
thanksssssssssssssssssss
you are right i will change the code thanks again for your help
Last edited on
Topic archived. No new replies allowed.