Results 1 to 4 of 4

Thread: what is the difference between this two programs, I am talking about code behaviour

  1. #1
    Join Date
    Oct 2016
    Posts
    10
    Platforms
    Windows

    Default what is the difference between this two programs, I am talking about code behaviour

    What I had in mind before creating this program was, to declare and create all the ATM customer accounts
    ( database ) within Cuenta.h so that I can call every single one of them from main just by typing for example

    Clase1 claseLuis( "Luis", 28, 3600 ) using program B or Clase1 ClaseLuis; using program A.

    Clase2 claseDiana( "Diana", 23, 2200 ) using program B or Clase2 ClaseDiana; using program A.

    Clase3 claseHector( "Hector", 26, 4500 ) using program B or Clase3 ClaseHector; using program A.

    Clase2 and Clase3 does not yet exists in my current code but I guess I can add them all within "Cuenta.h" and
    "cuenta.cpp"

    within main obviously, with their respective passwords set for each one of them, but I wonder which program
    is preferable to use "Program A or Program B"???

    Qt Code:
    1. //****************( "Cuenta.h " )****************Part_Of_Program_"A"
    2.  
    3. #include<string>
    4. using namespace std;
    5.  
    6. class Cuenta1{
    7.  
    8. public:
    9.  
    10. Cuenta1();
    11.  
    12. void establecerValores( string, int, int );
    13.  
    14. string obtenerUsuario( );
    15.  
    16. int obtenerEdad();
    17.  
    18. int obtenerMonto();
    19.  
    20. void pedirContrasenia();
    21.  
    22. void mostrarMensaje();
    23.  
    24. private:
    25.  
    26. string nombreUsuario;
    27. int edadUsuario;
    28. int montoUsuario;
    29. int contraseniaUsuario;
    30. };
    31.  
    32. //****************( " end of Cuenta.h " )****************Part_Of_Program_"A"
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************( " Cuenta.cpp " )****************Part_Of_Program_"A"
    2.  
    3. #include<iostream>
    4. #include"Cuenta.h"
    5. using namespace std;
    6.  
    7. Cuenta1::Cuenta1(){
    8.  
    9. establecerValores( "Luis Alberto Sánchez M", 28, 3600 );
    10. }
    11.  
    12. void Cuenta1::establecerValores( string nombre, int edad, int monto ){
    13.  
    14. nombreUsuario = nombre;
    15. edadUsuario = edad;
    16. montoUsuario = monto;
    17. pedirContrasenia();
    18. }
    19.  
    20. string Cuenta1::obtenerUsuario(){
    21.  
    22. return nombreUsuario;
    23. }
    24.  
    25. int Cuenta1::obtenerEdad(){
    26.  
    27. return edadUsuario;
    28. }
    29.  
    30. int Cuenta1::obtenerMonto(){
    31.  
    32. return montoUsuario;
    33. }
    34.  
    35. void Cuenta1::pedirContrasenia(){
    36.  
    37. int contraseniaActual = 1988;
    38. cout << "Por favor introduzca su contraseña : ";
    39. cin >> contraseniaUsuario;
    40. cout << "\n\n";
    41.  
    42. if( contraseniaUsuario == contraseniaActual )
    43.  
    44. mostrarMensaje();
    45.  
    46. if( contraseniaUsuario != contraseniaActual )
    47.  
    48. cout << "\n\n";
    49. cout << "Usted ingreso una contraseña incorrecta se se reinicializara el sistema\n"
    50. << "por favor introduzca la contraseña correcta la proxima vez" << "\n\n" ;
    51.  
    52. }
    53.  
    54. void Cuenta1::mostrarMensaje(){
    55.  
    56. cout << "Bienvenido a cajeros Nature : " << obtenerUsuario() << " Edad " << obtenerEdad() << "usted tiene $ " << obtenerMonto() << "\n\n";
    57. }
    58.  
    59. //****************( " end of cuenta.cpp " )****************Part_Of_Program_"A"
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************( " main.cpp " )****************Part_Of_Program_"A"
    2.  
    3. #include<iostream>
    4. #include<cstdlib>
    5. #include "Cuenta.h"
    6. using namespace std;
    7.  
    8. int main(){
    9.  
    10. Cuenta1 cuentaLuis;
    11.  
    12. system("PAUSE");
    13. return 0;
    14. }
    15.  
    16. //****************( " end of main.cpp " )****************Part_Of_Program_"A"
    To copy to clipboard, switch view to plain text mode 


    ---------------------------------------------------------------------------------------------------------------------------------------------------------


    Qt Code:
    1. //****************( "Cuenta.h " )****************Part_Of_Program_"B"
    2.  
    3. #include<string>
    4. using namespace std;
    5.  
    6. class Cuenta1{
    7.  
    8. public:
    9.  
    10. Cuenta1( string, int, int );
    11.  
    12. void establecerValores( string, int, int );
    13.  
    14. string obtenerUsuario( );
    15.  
    16. int obtenerEdad();
    17.  
    18. int obtenerMonto();
    19.  
    20. void pedirContrasenia();
    21.  
    22. void mostrarMensaje();
    23.  
    24. private:
    25.  
    26. string nombreUsuario;
    27. int edadUsuario;
    28. int montoUsuario;
    29. int contraseniaUsuario;
    30. };
    31.  
    32. //****************( " end of Cuenta.h " )****************Part_Of_Program_"B"
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************( " Cuenta.cpp " )****************Part_Of_Program_"B"
    2.  
    3. #include<iostream>
    4. #include"Cuenta.h"
    5. using namespace std;
    6.  
    7. Cuenta1::Cuenta1( string nombre, int edad, int monto ){
    8.  
    9. establecerValores( nombre, edad, monto );
    10. }
    11.  
    12. void Cuenta1::establecerValores( string nombre, int edad, int monto ){
    13.  
    14. nombreUsuario = nombre;
    15. edadUsuario = edad;
    16. montoUsuario = monto;
    17. pedirContrasenia();
    18. }
    19.  
    20. string Cuenta1::obtenerUsuario(){
    21.  
    22. return nombreUsuario;
    23. }
    24.  
    25. int Cuenta1::obtenerEdad(){
    26.  
    27. return edadUsuario;
    28. }
    29.  
    30. int Cuenta1::obtenerMonto(){
    31.  
    32. return montoUsuario;
    33. }
    34.  
    35. void Cuenta1::pedirContrasenia(){
    36.  
    37. int contraseniaActual = 1988;
    38. cout << "Por favor introduzca su contraseña : ";
    39. cin >> contraseniaUsuario;
    40. cout << "\n\n";
    41.  
    42. if( contraseniaUsuario == contraseniaActual )
    43.  
    44. mostrarMensaje();
    45.  
    46. if( contraseniaUsuario != contraseniaActual )
    47.  
    48. cout << "\n\n";
    49. cout << "Usted ingreso una contraseña incorrecta se se reinicializara el sistema\n"
    50. << "por favor introduzca la contraseña correcta la proxima vez" << "\n\n" ;
    51.  
    52. }
    53.  
    54. void Cuenta1::mostrarMensaje(){
    55.  
    56. cout << "Bienvenido a cajeros Nature : " << obtenerUsuario() << " Edad " << obtenerEdad() << "usted tiene $ " << obtenerMonto() << "\n\n";
    57. }
    58.  
    59. //****************( " end of cuenta.cpp " )****************Part_Of_Program_"B"
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************( " main.cpp " )****************Part_Of_Program_"B"
    2.  
    3. #include<iostream>
    4. #include<cstdlib>
    5. #include "Cuenta.h"
    6. using namespace std;
    7.  
    8. int main(){
    9.  
    10. Cuenta1 cuentaLuis( "Luis Alberto Sanchez M", 28, 3600 );
    11.  
    12. system("PAUSE");
    13. return 0;
    14. }
    15.  
    16. //****************( " end of main.cpp " )****************Part_Of_Program_"B"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is the difference between this two programs, I am talking about code behavio

    You really don't want to need different classes for different values, but one class for the type of data and instances for each value.

    I.e. one class that can hold the information for a single customer and one instance of that class for each customer.

    So what your program B does.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2016
    Posts
    10
    Platforms
    Windows

    Default Re: what is the difference between this two programs, I am talking about code behavio

    ok so know I modified the program to add the class functions retirarSaldo(), and abonarSaldo() and some private data.

    I also make use of: cuentaLuis.pedirContrasenia(); within main instead of within the constructor.
    and also cuentaDiana.pedirContrasenia();

    but for me the question remains why not to allow the constructor to do all the processing??.

    Will it cause conflicts by compiling the program that way or is just a matter of readability?

    how much further must I allow a constructor to handle the processing of any program?

    Qt Code:
    1. //****************( "Cuenta.h " )****************
    2.  
    3. #include<string>
    4. using namespace std;
    5.  
    6. class Cuenta1{
    7.  
    8. public:
    9.  
    10. Cuenta1( string, int, int, int, string );
    11.  
    12. void establecerValores( string, int, int, int, string );
    13.  
    14. string obtenerUsuario( );
    15.  
    16. int obtenerEdad();
    17.  
    18. int obtenerMonto();
    19.  
    20. void pedirContrasenia();
    21.  
    22. void mostrarMensaje();
    23.  
    24. void retirarSaldo( int );
    25.  
    26. void depositarSaldo( int );
    27.  
    28. private:
    29.  
    30. string nombreUsuario;
    31. int edadUsuario;
    32. int montoUsuario;
    33. int contraseniaUsuario;
    34. string referenciaUsuario;
    35. };
    36.  
    37. //****************( " end of Cuenta.h " )****************
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************( " Cuenta.cpp " )****************
    2.  
    3. #include<iostream>
    4. #include"Cuenta.h"
    5. using namespace std;
    6.  
    7. Cuenta1::Cuenta1( string nombre, int edad, int monto, int contrasenia, string referencia ){
    8.  
    9. establecerValores( nombre, edad, monto, contrasenia, referencia );
    10. }
    11.  
    12. void Cuenta1::establecerValores( string nombre, int edad, int monto, int contrasenia, string referencia ){
    13.  
    14. nombreUsuario = nombre;
    15. edadUsuario = edad;
    16. montoUsuario = monto;
    17. contraseniaUsuario = contrasenia;
    18. referenciaUsuario = referencia;
    19. }
    20.  
    21. string Cuenta1::obtenerUsuario(){
    22.  
    23. return nombreUsuario;
    24. }
    25.  
    26. int Cuenta1::obtenerEdad(){
    27.  
    28. return edadUsuario;
    29. }
    30.  
    31. int Cuenta1::obtenerMonto(){
    32.  
    33. return montoUsuario;
    34. }
    35.  
    36. void Cuenta1::pedirContrasenia(){
    37.  
    38. int contraseniaActual;
    39. cout << "Por favor : " << referenciaUsuario << " introduzca su contraseña : ";
    40. cin >> contraseniaActual;
    41. cout << "\n\n";
    42.  
    43. if( contraseniaActual == contraseniaUsuario ){
    44.  
    45. mostrarMensaje();
    46. }
    47.  
    48. if( contraseniaActual != contraseniaUsuario ){
    49.  
    50. cout << "\n\n";
    51. cout << "Usted ingreso una contraseña incorrecta se se reinicializara el sistema\n"
    52. << "por favor introduzca la contraseña correcta la proxima vez" << "\n\n" ;
    53. }
    54.  
    55. }
    56.  
    57. void Cuenta1::mostrarMensaje(){
    58.  
    59. int opcion;
    60. int cantidadRetiro;
    61. int cantidadAbono;
    62. cout << "Bienvenido a cajeros Nature : " << obtenerUsuario() << " Edad " << obtenerEdad() << " usted tiene $ " << obtenerMonto() << "\n\n";
    63. cout << "\n\nque desea realizar? \t1)Retiro\t2)Deposito? ";
    64. cin >> opcion;
    65.  
    66. if( opcion == 1 ){
    67.  
    68. cout << "\n\nCout Cuanto desea retirar? ";
    69. cin >> cantidadRetiro;
    70. retirarSaldo( cantidadRetiro );
    71. }
    72.  
    73. if( opcion == 2 ){
    74.  
    75. cout << "\n\nCuanto desea abonar? ";
    76. cin >> cantidadAbono;
    77. depositarSaldo( cantidadAbono );
    78. }
    79. }
    80.  
    81. void Cuenta1::retirarSaldo( int monto ){
    82.  
    83. if(( montoUsuario - monto ) < 0 ){
    84.  
    85. montoUsuario = montoUsuario;
    86.  
    87. cout << "\n\nUsted no puede retirar mas de lo que tiene : " << obtenerMonto() << "\n\n";
    88. }
    89.  
    90. if(( montoUsuario - monto ) == 0 ){
    91.  
    92. montoUsuario = montoUsuario - monto;
    93.  
    94. cout << "\n\nUsted retiro : " << monto << " Su saldo actual es : " << obtenerMonto() << "\n\n";
    95. }
    96.  
    97. if(( montoUsuario - monto ) > 0 ){
    98.  
    99. montoUsuario = montoUsuario - monto;
    100.  
    101. cout << "\n\nUsted retiro : " << monto << " Su saldo actual es : " << obtenerMonto() << "\n\n";
    102. }
    103. }
    104.  
    105. void Cuenta1::depositarSaldo( int monto ){
    106.  
    107. if(( montoUsuario <= 0)){
    108.  
    109. montoUsuario = montoUsuario + monto;
    110.  
    111. cout << "\n\nUsted deposito : " << monto << " su saldo actual es : " << obtenerMonto() << "\n\n";
    112. }
    113.  
    114. if(( montoUsuario > 0 )){
    115.  
    116. montoUsuario = montoUsuario + monto;
    117.  
    118. cout << "\n\nUsted deposito : " << monto << " su saldo actual es : " << obtenerMonto() << "\n\n";
    119. }
    120. }
    121.  
    122. //****************( " end of cuenta.cpp " )****************
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************( " main.cpp " )****************
    2.  
    3. #include<iostream>
    4. #include<cstdlib>
    5. #include "Cuenta.h"
    6. using namespace std;
    7.  
    8. int main(){
    9.  
    10. Cuenta1 cuentaLuis( "Luis Alberto Sanchez M", 28, 3600, 1988, "Luis" );
    11. cuentaLuis.pedirContrasenia();
    12. Cuenta1 cuentaDiana( "Diana Carolina Sanchez M", 25, 4500, 1991, "Diana" );
    13. cuentaDiana.pedirContrasenia();
    14.  
    15. system("PAUSE");
    16. return 0;
    17. }
    18.  
    19. //****************( " end of main.cpp " )****************
    To copy to clipboard, switch view to plain text mode 

    also in the part of my code where I make use of Cuenta1::mostrarMensaje(), originally I wanted the program to decide depending on the input of the user if option "a" user input were "A" and option b user input were "B" using getline( cin, opcion ) where "opcion" is a string variable whether it can be "A" or "B" but it does not seems to work that way that is why i used an int variable "opcion" to make the work done, still I am curious about changing that part of my code so that the input of the user is "A" or "B" rather than 1 or 2.

    Qt Code:
    1. string opcion;
    2. getline( cin, opcion )
    3.  
    4. if( opcion == "A" ){
    5.  
    6. cout << "\n\nCout Cuanto desea retirar? ";
    7. cin >> cantidadRetiro;
    8. retirarSaldo( cantidadRetiro );
    9. }
    10.  
    11. if( opcion == "B" ){
    12.  
    13. cout << "\n\nCuanto desea abonar? ";
    14. cin >> cantidadAbono;
    15. depositarSaldo( cantidadAbono );
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: what is the difference between this two programs, I am talking about code behavio

    Quote Originally Posted by sauerplayer View Post
    I also make use of: cuentaLuis.pedirContrasenia(); within main instead of within the constructor.
    and also cuentaDiana.pedirContrasenia();

    but for me the question remains why not to allow the constructor to do all the processing??.
    You are mixing questions/answers from two different threads.
    jefftee answered that one on the other thread.

    Quote Originally Posted by sauerplayer View Post
    Will it cause conflicts by compiling the program that way or is just a matter of readability?
    As it compiled for you it couldn't have caused conflicts for compiling, could it?

    Quote Originally Posted by sauerplayer View Post
    how much further must I allow a constructor to handle the processing of any program?
    A constructor initializes an object of a class. It has to do whatever is necessary to achieve that.
    It can do other things as well, but again, see jefftee's comments in your other thread.

    Quote Originally Posted by sauerplayer View Post
    also in the part of my code where I make use of Cuenta1::mostrarMensaje(), originally I wanted the program to decide depending on the input of the user if option "a" user input were "A" and option b user input were "B" using getline( cin, opcion ) where "opcion" is a string variable whether it can be "A" or "B" but it does not seems to work that way that is why i used an int variable "opcion" to make the work done, still I am curious about changing that part of my code so that the input of the user is "A" or "B" rather than 1 or 2.
    What have you debugged so far?
    Is the input either "A" or "B"?

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 29th July 2015, 08:40
  2. What is the difference between (.) and (->) on this code
    By rezas1000 in forum General Programming
    Replies: 2
    Last Post: 30th August 2014, 17:02
  3. Replies: 2
    Last Post: 22nd March 2014, 11:32
  4. Qt 5.0.1 MinGW - programs does not launch - exited with code 0xc0000139
    By Sébastien in forum Installation and Deployment
    Replies: 8
    Last Post: 10th April 2013, 12:22
  5. Difference in layout behaviour in Qt 4.4 and Qt 4.7.4
    By Raghaw in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2011, 10:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.