Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3.  
  4. using namespace std;
  5.  
  6. class CMhs {
  7. private:
  8. char*NRP, *Nama, *Prodi;
  9. float IPK;
  10. int sks;
  11. public:
  12. CMhs() {
  13. NRP = new char[15];
  14. Nama = new char[20];
  15. Prodi = new char[20];
  16. IPK = 4.0;
  17. sks = 24;
  18. }
  19. CMhs(char*nrp, char*nama, char*prodi, float ipk, int SKS) {
  20. NRP = new char[15];
  21. Nama = new char[20];
  22. Prodi = new char[20];
  23. strcpy(NRP, nrp);
  24. strcpy(Nama, nama);
  25. strcpy(Prodi, prodi);
  26. IPK = ipk;
  27. if (SKS != NULL)
  28. {
  29. sks = SKS;
  30. }
  31. else
  32. {
  33. if (ipk <= 3.0)
  34. {
  35. sks = 20;
  36. }
  37. else {
  38. sks = 24;
  39. }
  40. }
  41. }
  42. CMhs(const CMhs &a) {
  43. NRP = new char[15];
  44. Prodi = new char[strlen(a.Prodi)];
  45. Nama = new char[strlen(a.Nama)];
  46. strcpy(NRP, a.NRP);
  47. strcpy(Nama, a.Nama);
  48. strcpy(Prodi, a.Prodi);
  49. IPK = a.IPK;
  50. sks = a.sks;
  51. }
  52.  
  53. void setNama(const char*a) {
  54. Nama = new char[20];
  55. strcpy(Nama, a);
  56. }
  57. void setIPK(float a) {
  58. IPK = a;
  59. if (a <= 3.0)
  60. {
  61. sks = 20;
  62. }
  63. else {
  64. sks = 24;
  65. }
  66. }
  67. void display();
  68. };
  69.  
  70. void CMhs::display() {
  71. cout << "NRP\t" << "Nama\t" << "Prodi\t" << "IPK\t" << "SKS Ambil\n";
  72. cout << NRP << "\t" << Nama << "\t" << Prodi << "\t" << IPK << "\t" << sks << endl;
  73. }
  74.  
  75. void main() {
  76. CMhs A("C14170900", "Dina", "Informatika", 3.49, 23) , B , C[10];
  77. B = A;
  78. B.setNama("Dini"); B.setIPK(2.5);
  79. A.display();
  80. B.display();
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement