CRUD

Can someone help me to delete the float values in my code?
error : type 'flooat' argument given to 'delete', expected pointer


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
int grade;
string error = "Please try it again";
string compiled_grades;
string remove_grade;
vector<string> AllGrades;
char choice;
float AD_HPS = 60.00;
float HOA_HPS = 60.00 ;
float Q_HPS = 30.00 ;
float ME_HPS = 50.00;
float AD_GRADE; // HPS 60
float HOA_GRADE; // HPS 60
float Q_GRADE; // HPS 30
float ME_GRADE; // HPS 50
float FINAL_GRADE;

do{
//try {
cout <<"\n Calculate Grades for " ;
cout << "\n A. Assignmens/Discussion" << endl;
cout << " B. Hands on Activity" << endl;
cout << " C. Quizzes" << endl;
cout << " D. Exams" << endl;
cout << " E. Final Grades" << endl;
cout << " F. Delete Grades" << endl;
cout << " G. Show all Grades" << endl;
cout << " H. Quit program \n " <<endl;
cin >> choice;
if(choice == 'H') {
printf("Terminating the program");
}
//else{
//if (choice <= 0)
//{
//throw error;
//}
if(choice == 'A'|| choice == 'a'){
cout << "Please enter the grade for Assignment and Discussion " ;
cin >> grade;
AD_GRADE = (grade/AD_HPS*0.15*100);
cout <<fixed <<showpoint <<setprecision(2);
cout <<"\nYour grade for Assignment and Discussion is : " <<AD_GRADE;
AllGrades.push_back(compiled_grades);
cout << "\nGrade has been added" << endl;

}else if(choice =='B' || choice == 'b'){
cout << "Please enter the grade for Hands on Activity " ;
cin >> grade;
HOA_GRADE = (grade/HOA_HPS*0.15*100);
cout <<fixed <<showpoint <<setprecision(2);
cout <<"\nYour grade for Hands on Activity is : " <<HOA_GRADE;
AllGrades.push_back(compiled_grades);
cout << "\nGrade has been added" << endl;

}else if(choice == 'C' || choice == 'c'){
cout << "Please enter the grade for Quizzes" << endl;
cin >> grade;
Q_GRADE= ( grade / Q_HPS*0.2*100);
cout <<fixed <<showpoint <<setprecision(2);
cout <<"\nYour grade for Quizzes is : " <<Q_GRADE;
AllGrades.push_back(compiled_grades);
cout << "\nGrade has been added" << endl;

}else if(choice == 'D'|| choice == 'd'){
cout << "Please enter the grade for Exams" << endl;
cin>>grade;
ME_GRADE= ( grade / ME_HPS*0.5*100);
cout <<fixed <<showpoint <<setprecision(2);
cout <<"\nYour grade for Exams is : " <<ME_GRADE;
AllGrades.push_back(compiled_grades);
cout << "\nGrade has been added";

}else if(choice == 'E' || choice == 'e'){
cout << "\nFINAL GRADE" ;
FINAL_GRADE = AD_GRADE + HOA_GRADE + Q_GRADE + ME_GRADE;
cout <<fixed <<showpoint <<setprecision(2);
AllGrades.push_back(compiled_grades);
cout << " Your Final Grade is : " <<FINAL_GRADE;
}
else if (choice == 'F' || choice == 'f'){
for(int i = 0; i < 1 ; ++i)

delete AD_GRADE;
delete HOA_GRADE;
delete Q_GRADE;
delete ME_GRADE;
delete FINAL_GRADE;
cout <<" \nAD_GRADE "<<AD_GRADE;
cout <<" \nHOA_GRADE "<<HOA_GRADE;
cout <<" \nQ_GRADE "<<Q_GRADE;
cout <<" \nME_GRADE "<<ME_GRADE;
cout <<" \nFE_GRADE "<<FINAL_GRADE;


}
else if(choice == 'G' || choice == 'g '){
cout << "All Grades in the Array";
for(int i = 0; i < 1 ; ++i){
cout <<" \nAD_GRADE "<<AD_GRADE;
cout <<" \nHOA_GRADE "<<HOA_GRADE;
cout <<" \nQ_GRADE "<<Q_GRADE;
cout <<" \nME_GRADE "<<ME_GRADE;
cout <<" \nFE_GRADE "<<FINAL_GRADE;
}
}



//catch (string error)
//{
//cout <<"There's a problem in choices you input. " <<error;
//}
}
while(choice != 'H');
return 0;
}
Last edited on
Why you do you think you need to call delete <float>? Because, you don't.
delete is part of a new/delete pairing. if you do not use new, you should not use delete.
new is a request to the operating system for a block of memory outside the program's normal operating memory space. Delete gives it back to the OS, as you are done with it. This is 'dynamic memory' and best avoided (let C++ containers do it for you most of the time), which is a subset of the many ways to use pointer variable types.
@OP It appears you are using CRUD as in database-speak. The reason your delete doesn’t work is because ‘delete’ is a C++ keyword and you are mis-using it. Since you are storing the data items in a vector the correct operation is to erase the item. You need to read up on the <vector> reference material for the erase() function. Use a better interface function name than Delete or especially delete or Erase or erase ... delete_an_item() maybe.

You might also like to consider encapsulating the various grades in a single structure or class because on first glance it appears your data model using a single vector to store separate grades is no good.

You can easily consolidate, simplify and make clearer a lot of your code using a switch associated with your menu.
do you have any alternative code to at least erase the inputs on whatever I put on the cin>> grade?
Best advice is to post the question you have been asked exactly as it is in your assignment. You will be able to erase a value but I suspect your data model is going to presents you with nightmares.

However, if you have a <vector> of integers, putting aside all your assignment stuff, the way to erase an item from the vector is described in the reference on this site, amongst zillions of others. Like this one, the good ones have examples to support the explanations.

http://www.cplusplus.com/reference/vector/vector/erase/

The essence is to decide which element of the vector it is you don't want and
1
2
// erase the 6th element
  myvector.erase (myvector.begin()+5);


Another vector method that might be useful is myvector.clear(); a one-liner that removes all vector elements.
https://www.cplusplus.com/reference/vector/vector/clear/
Last edited on
This might be useful as a start to solving a few riddles but in now way is complete. A single <vector> of int's is possible but hardly practical. Parallel <vector>'s could be a solution. A vector of StudentRecords is ideal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <iomanip>
#include <string> // NOT USED YET MAYBE USE FOR A STUDENT NAME ??
#include <vector>

using namespace std;

int main()
{
    int grade;
    
    vector<double> AllGrades; // vector<StudentRecord>??
    
    char choice;
    
    double AD_HPS = 60.00;
    double HOA_HPS = 60.00 ;
    double Q_HPS = 30.00 ;
    double ME_HPS = 50.00;
    
    // struct StudentRecord??
    double AD_GRADE{0.};
    double HOA_GRADE{0.};
    double Q_GRADE{0.};
    double ME_GRADE{0.};
    
    double FINAL_GRADE{0};
    
    do{
        cout
        << '\n'
        << "*** CALCULATE GRADES FOR: "
        << '\n'
        << " A. Assignmens/Discussion\n"
        << " B. Hands on Activity\n"
        << " C. Quizzes\n"
        << " D. Exams\n"
        << " E. Final Grades\n"
        << " F. Delete Grades\n"
        << " G. Show all Grades\n"
        << " H. Quit program\n"
        << '\n'
        << "*** PLEASE ENTER SELECTION: ";
        
        cin >> choice;
        
        choice = toupper(choice);
        
        switch(choice)
        {
            case 'H':
                cout << "Terminating the program\n";
                break;
                
            case 'A':
                cout << "Please enter the grade for Assignment and Discussion: " ;
                cin >> grade;
                AD_GRADE = (grade/AD_HPS*0.15*100);
                
                cout << fixed << showpoint << setprecision(2);
                cout <<"Your grade for Assignment and Discussion is: " << AD_GRADE << '\n';
                
                AllGrades.push_back(AD_GRADE);
                cout << "Grade has been added\n";
                break;
                
            case 'B':
                cout << "Please enter the grade for Hands on Activity " ;
                cin >> grade;
                HOA_GRADE = (grade/HOA_HPS*0.15*100);
                
                cout
                << fixed <<showpoint << setprecision(2)
                << "Your grade for Hands on Activity is : " <<HOA_GRADE << '\n';
               
                AllGrades.push_back(HOA_GRADE);
                cout << "Grade has been added\n";
                break;
                
            case 'C':
                cout << "Please enter the grade for Quizzes" << endl;
                cin >> grade;
                Q_GRADE= ( grade / Q_HPS*0.2*100);
                
                cout
                << fixed << showpoint << setprecision(2)
                << "Your grade for Quizzes is : " << Q_GRADE << '\n';
                
                AllGrades.push_back(Q_GRADE);
                cout << "Grade has been added\n";
                break;
                
            case 'D':
                cout << "Please enter the grade for Exams\n";
                cin >> grade;
                ME_GRADE = ( grade / ME_HPS*0.5*100);
               
                cout
                << fixed << showpoint << setprecision(2)
                << "Your grade for Exams is : " << ME_GRADE << '\n';
                
                AllGrades.push_back(ME_GRADE);
                cout << "Grade has been added\n";
                break;
                
            case 'E':
                cout << "FINAL GRADE\n" ;
                FINAL_GRADE = AD_GRADE + HOA_GRADE + Q_GRADE + ME_GRADE;
                cout
                << fixed << showpoint << setprecision(2)
                << " Your Final Grade is : " << FINAL_GRADE << '\n';
                
                AllGrades.push_back(FINAL_GRADE);
                cout << "Grade has been added\n";
                break;
                
            case 'F': // MAYBE SEARCH ON STUDENT NAME??
                AllGrades.clear();
                break;
                
            case 'G': // THIS NEEDS A LOT OF WORK cf struct or CLASS
                cout << "All Grades in the Array\n";
                
                for(int i = 0; i < AllGrades.size() ; i++)
                {
                    cout
                    << " AD_GRADE " << AD_GRADE << '\n'
                    << " HOA_GRADE "<< HOA_GRADE  << '\n'
                    << " Q_GRADE " << Q_GRADE << '\n'
                    << " ME_GRADE " << ME_GRADE << '\n'
                    << " FE_GRADE " << FINAL_GRADE << '\n';
                }
                break;
                
            default:
                cout << "Invalid choice please try again\n";
                break;
        }
    } while(choice != 'H');
    
    cout << "Program terminated\n";
    return 0;
}
wow sir thank you for your help I appreciated so much ^_^
:)

Not the full story but ...
By concentrating code on individual processes with functions and sub menus it's pretty straightforward to make a workable database even save the list of records to/from permanent storage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <iomanip>
#include <string>
#include <vector> // A <map> IS EVEN BETTER

using namespace std;

struct StudentRecord
{
    string name{"???"};
    double ad_grade{0.};
    double hoa_grade{0.};
    double q_grade{0.};
    double me_grade{0.};
    
    double getFinalGrade()
    {
        double AD_HPS = 60.00;
        double HOA_HPS = 60.00 ;
        double Q_HPS = 30.00 ;
        double ME_HPS = 50.00;
        
        double AD_GRADE = ad_grade/AD_HPS*0.15*100;
        double HOA_GRADE = hoa_grade/HOA_HPS*0.15*100;
        double Q_GRADE = q_grade / Q_HPS*0.2*100;
        double ME_GRADE =  me_grade / ME_HPS*0.5*100;
        
        return AD_GRADE + HOA_GRADE + Q_GRADE + ME_GRADE;
    }
};

char CRUD_menu()
{
    char selection{'?'};
    
    cout
    << ">\n"
    << "*** SELECT FROM ***\n"
    << "C - create new record\n"
    << "R - read an existing record\n"
    << "U - update an existing record\n"
    << "D - delete an existing record\n"
    << "Q - quit\n"
    << "Please enter selection: ";
    
    cin >> selection;
    
    cout << "Menu selection is: " << selection << "  ->  " ;
    
    return toupper(selection);
}

int main()
{
    vector<StudentRecord> student_records;
    char choice{'*'};
    
    while( (choice = CRUD_menu()) && (choice != 'Q') )
    {
        cout
        << "Selection is: " << choice << "  ->  ";
        
        switch(choice)
        {
            case 'C':
            {
                cout << "Create a record(s)\n";
                
                // SOME DEMO JUNK
                StudentRecord temp;
                StudentRecord temp1{"Betty", 23, 98, 83, 12};
                StudentRecord temp2{"Bill", 75, 80, 10, 6};
                
                student_records.push_back(temp);
                student_records.push_back(temp1);
                student_records.push_back(temp2);
                
                cout
                << "No. of students "
                << student_records.size() << '\n';
                
                break;
            }
            case 'R':
                cout << "Read a record\n";
                cout << "All students names and final grades\n";
                for(int i = 0; i < student_records.size(); i++)
                {
                    cout
                    << student_records[i].name << ' '
                    << student_records[i].getFinalGrade() << '\n';
                }
                break;
            case 'U':
                cout << "Update a record\n";
                break;
            case 'D':
                cout << "Delete a record\n";
                break;
            default:
                cout << "ERROR: invalid selection\n";
        }
    }
    
    cout << "Program terminated\n";
    return 0;
}


>
*** SELECT FROM ***
C - create new record
R - read an existing record
U - update an existing record
D - delete an existing record
Q - quit
Please enter selection: c
Menu selection is: c  ->  Selection is: C  ->  Create a record(s)
No. of students 3
>
*** SELECT FROM ***
C - create new record
R - read an existing record
U - update an existing record
D - delete an existing record
Q - quit
Please enter selection: r
Menu selection is: r  ->  Selection is: R  ->  Read a record
All students names and final grades
??? 0
Betty 97.5833
Bill 51.4167
>
*** SELECT FROM ***
C - create new record
R - read an existing record
U - update an existing record
D - delete an existing record
Q - quit
Please enter selection: q
Menu selection is: q  ->  Program terminated
Program ended with exit code: 0
Last edited on
Topic archived. No new replies allowed.