468,167 Members | 1,958 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,167 developers. It's quick & easy.

I need help how to add a subject code in this coding.

1 Bit
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <limits>
  5.  
  6. using namespace std;
  7.  
  8. class student
  9. {
  10.     string name;
  11.     string id;
  12.     int credit[46];
  13.     float pointer[46];
  14.     float gpa[8];
  15.     float totalCredit;
  16.     float cgpa=0;
  17.     float sumTotalCredit;
  18.     float credpoint;
  19.     int sem, currentSub;
  20.     float x;
  21.     float sumCredPoint;
  22.  
  23.     public:
  24.  
  25.     float getTotalCredit()
  26.     {
  27.         return totalCredit;
  28.     }
  29.  
  30.     void setTotalCredit(float t)
  31.     {
  32.         totalCredit=t;
  33.     }
  34.  
  35.     float getSumTotalCredit()
  36.     {
  37.         return sumTotalCredit;
  38.     }
  39.  
  40.     void setSumTotalCredit(float c)
  41.     {
  42.         sumTotalCredit=c;
  43.     }
  44.  
  45.     float CalculateGpa(float i,int k){
  46.  
  47.         return i/k;
  48.     }
  49.  
  50.     float getCredPoint()
  51.     {
  52.         return credpoint;
  53.     }
  54.  
  55.     void setCredPoint(float r)
  56.     {
  57.         credpoint=r;
  58.     }
  59.     float getCurrentSub()
  60.     {
  61.         return currentSub;
  62.     }
  63.  
  64.     void setCurrentSub(int s)
  65.     {
  66.         currentSub=s;
  67.     }
  68.  
  69.     float getSumCredPoint()
  70.     {
  71.         return sumCredPoint;
  72.     }
  73.  
  74.     student(string name,string id)
  75.     {
  76.         this->name=name;
  77.         this->id=id;
  78.     }
  79.  
  80.     string getName()
  81.     {
  82.         return name;
  83.     }
  84.  
  85.         string getId()
  86.     {
  87.         return id;
  88.     } };
  89.  
  90.         int main()
  91.         {
  92.     /*system("color 07");
  93.      cout<<"\n\n\n\tPlease wait while loading ..\n\n";
  94.      char a=177, b=219;
  95.     cout<<"\t      ";
  96.     for (int i=0;i<=12;i++)
  97.     cout<<a;
  98.     cout<<"\r";
  99.      cout<<"\t      ";
  100.      for (int i=0;i<=12;i++)
  101.      { cout<<b;
  102.       for (int j=0;j<=1e8;j++); }*/
  103.  
  104.     system("cls");
  105.  
  106.         ofstream myfile;
  107.         myfile.open("Transcript.txt");
  108.  
  109.     int Choice;
  110.  
  111.     cout<<"\n Examination Result"<<endl;
  112.     cout<<"\n\t1) Faculty of Computing"<<endl;
  113.  
  114.     cout<<"\n\tPlease enter the number of your faculty: ";
  115.         cin>>Choice;
  116.  
  117.         system("cls");
  118.  
  119.     cout<<"\n Examination Result"<<endl;
  120.  
  121.     switch (Choice){
  122.     case 1 :
  123.     cout<<"\n\tFaculty: Faculty of Computing"<<endl;
  124.     break; }
  125.  
  126.     if (Choice==1){
  127.  
  128.     cout<<"\n\tList of our courses:"<<endl;
  129.     cout<<"\t1) SCSR (Computer Network & Security)"<<endl;
  130.  
  131.         cout<<"\n\tPlease enter the number of your course: ";
  132.         cin>>Choice;
  133.         if (Choice !=1) {cout<<"\n\tChoice not valid. Please exit ! xD";
  134.         return 0;  }
  135.  
  136.         system("cls");
  137.  
  138.     myfile<<cout<<"\n Examination Result"<<endl;
  139.  
  140.     cout<<"\n Examination Result"<<endl;
  141.  
  142.     myfile<<"\n\tFaculty: Faculty of Computing"<<endl;
  143.     cout<<"\n\tFaculty: Faculty of Computing"<<endl;
  144.  
  145.     myfile<<"\tCourse : SCSR (Computer Network & Security)"<<endl;
  146.  
  147.         switch (Choice){
  148.     case 1 :
  149.     cout<<"\tCourse: SCSJ (Computer Network & Security)"<<endl;
  150.     break;
  151.     }  }
  152.  
  153.     else { cout<<"\n\tSorry ! We're currently working on this. xD"<<endl;
  154.     return 0;
  155.     };
  156.  
  157.     string* subject=new string[46];
  158.     string studentname;
  159.     string matricid;
  160.     bool bFail;
  161.  
  162.     cin.ignore();
  163.  
  164.     do {
  165.     cout<<"\n\tStudent Name: ";
  166.  
  167.     getline (cin,studentname);
  168.     bFail=cin.fail();
  169.         }  while (bFail==true);
  170.  
  171.     cout<<"\tMatric Number: ";
  172.     cin>>matricid;
  173.  
  174.     student st1(studentname, matricid);
  175.  
  176.     subject[0]="Discrete Structure                            ";
  177.     subject[1]="Programming Technique I                       ";
  178.     subject[2]="Technology & Information Systems              ";
  179.     subject[3]="Digital Logic                                 ";
  180.     subject[4]="Graduate Success Attributes                   ";
  181.     subject[5]="Malaysian Dynamic/ Malaysian Studies          ";
  182.  
  183.  
  184.     int credit[46];
  185.     float pointer[46];
  186.     float gpa[8];
  187.     float totalCredit;
  188.     float cgpa=0;
  189.     float sumTotalCredit;
  190.     float credpoint;
  191.     int sem, currentSub;
  192.     float x;
  193.     float sumCredPoint;
  194.     cout << "\tCurrent Semester (Now): ";
  195.     cin >> sem;
  196.  
  197.     int k=0;
  198.  
  199.     for(int i=0; i < sem ; i++)
  200.     {
  201.     cout << "\n\n\tNumber of Subjects: ";
  202.     cin >> currentSub;
  203.  
  204.     cout<<"\t============================================================"<<endl;
  205.                         cout<<"\t\t\t\t SEMESTER " << i+1 <<endl;
  206.     cout<<"\t============================================================"<<endl;
  207.     cout<<"\tLIST OF SUBJECTS :\t\t       CREDIT HRS:"<<"  POINTER:"<<endl;
  208.  
  209.     myfile<<"\n\t============================================================"<<endl;
  210.                         myfile<<"\t\t\t\t SEMESTER " << i+1 <<endl;
  211.     myfile<<"\t============================================================"<<endl;
  212.     myfile<<"\tLIST OF SUBJECTS :\t\t       CREDIT HRS:"<<"  POINTER:"<<endl;
  213.  
  214.         for(int j=0; j < currentSub; j++)
  215.         {
  216.             cout << "\t" << subject[k];
  217.             myfile << "\t" << subject[k];
  218.  
  219.             cin >> credit[k];
  220.             myfile << credit[k];
  221.                 cout<<"\t\t\t\t\t\t\t      ";
  222.  
  223.                 cin >> pointer[k];
  224.                 myfile <<"\t\t"<<pointer[k]<<endl;
  225.             totalCredit = totalCredit + credit[k];
  226.             st1.setTotalCredit(totalCredit);
  227.             x = (credit[k]*pointer[k]);
  228.             credpoint = credpoint + x;
  229.             k++;    
  230.         }
  231.         gpa[i] = st1.CalculateGpa(credpoint,totalCredit);
  232.         sumTotalCredit = sumTotalCredit+totalCredit;
  233.         sumCredPoint = sumCredPoint + credpoint;
  234.         cgpa = sumCredPoint/sumTotalCredit;
  235.         x=0;
  236.         credpoint = 0;
  237.         totalCredit=0;
  238.  
  239.     cout<<"\t============================================================"<<endl;
  240.     cout << "\t\t\t\t         GPA = "<< gpa[i]<<" /"<<" CGPA = "<< cgpa << endl;
  241.  
  242.     myfile<<"\t============================================================"<<endl;
  243.     myfile<< "\t\t\t\t         GPA = "<< gpa[i]<<" /"<<" CGPA = "<< cgpa << endl;   
  244.     }
  245.     cout<<"\n\tStudent Name: "<<st1.getName()<<endl;
  246.     cout<<"\tMatric Number: "<<st1.getId()<<endl;
  247.     cout<<"\tThe Final CGPA (Latest): "<< cgpa <<endl;
  248.  
  249.     myfile<<"\n\tStudent Name : "<<st1.getName()<<endl;
  250.     myfile<<"\tMatric Number: "<<st1.getId()<<endl;
  251.     myfile<<"\tThe Final CGPA (Latest): "<< cgpa <<endl;
  252.  
  253.     return 0; 
  254. }
  255.  
Feb 4 '21 #1
2 1360
dev7060
413 Expert 256MB
I need help how to add a subject code in this coding.
What is not working when trying to do such?
Feb 4 '21 #2
Banfa
9,033 Expert Mod 8TB
From line 57 string* subject=new string[46]; it appears that currently the code just treats the subject as a string, its name. Now you want to have both a name and a code for a subject that would suggest that you need a class to hold both the name and code and then change this allocation, and all the subsequent places in the code subject is used.

Finally on the subject of best practice this code would be far better if it used one of the standard containers, std::vector or std::list, to contain subjects rather than allocating a dynamic array not all of which is used; it would also be more scalable.
Feb 4 '21 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by SallyBenjamin | last post: by
2 posts views Thread by Tony Girgenti | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.