CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2017
    Location
    sc
    Posts
    5

    Guys whye can I sum the score? --class RiskScore

    I make a RiskScore class. Here I made this class re-useable by making them separate like this:

    1. Header// Member function or class definition
    2. Source code or implementation// This where I put how and what the program does.
    3. The driver or main.// This the file that will execute the source code.

    Problems in text:
    My functions does wrong calculations. Please check the error.pdf. I am not sure why the math is wrong.
    Help me figure it out. Thanks.

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    #ifndef    RISKSCORE_H
    #define    RISKSCORE_H
    
    
    //Place a class in a separate file for re-usability
    
    class RiskScore
    	{
    
    	    int dataClass;
            int dataSpread;
    		double dataPercent;
            int dataBizuse;
            int dataEnviron;
            int sum;
            double overPercdata;
            string deviceName;
    
    public:
    		RiskScore(string, int, int, double, int, int ); //it shows all member functions
    		void setDeviceName(string);//name of devices involved
    		string getDeviceName();
    		void setDataClass(int);//data classification
    		int getDataClass();
    		void setDataSpread(int);//how widely the threat spread
    		int getDataSpread();
    		void setDataPercent(double);//percentage of data under risk
    		double getDataPercent();
    		void setDataBizuse(int);//highly, often and rarely used
    		int getDataBizuse();
    		void setDataEnviron(int);//environment in which data is used P/stage/T
    		int getDataEnviron();
            double riskPrior();//Calculate all attributes of the Risk score per device
    		void print()const;
    		double addCalc();//total sum up of the scores
    		void instruct();
    
    private:
    };
    
    #endif
    ****************************source code**************************************
    Code:
    #include <limits>
    #include <iostream>
    #include <stdexcept>
    #include <iomanip>
    #include "RiskScore.h";
    using namespace std;
    
    RiskScore::RiskScore(string deviceName_r,int dataClass_sum, int dataSpread_sum, double dataPercent_l, int dataBizuse_sum, int dataEnviron_sum)
    	{
    		setDeviceName(deviceName_r);//validation and store of device name
    		setDataClass(dataClass_sum);//validation and store of data class
    		setDataSpread(dataSpread_sum);//validation and store data incident spread
    		setDataPercent(dataPercent_l);//validation and store of device data percentage
    		setDataBizuse(dataBizuse_sum);//validation and store of device BIZ use
            setDataEnviron(dataEnviron_sum);//validation and store of device environment
    }
    
    void RiskScore::instruct()//program guide and detail
    {
                    cout << " This program is to help the department obtain the risk scores \n"<<endl;
                    cout << " for all security incident. In turn the department can use this \n"<<endl;
                    cout << " to tally up the financial lose that comes with the incidents. \n"<<endl;
                    cout << " This will help the department with budgeting for IT security. \n "<<endl;
    }
    
    void RiskScore::setDeviceName(string deviceName_r )
    {
                    deviceName=deviceName_r;
                    cout<<"\n Device Name"<<setw(20)<<"Value"<<endl;//header
                    cout<<setw(4)<<"STANDARD WORKSTATION"<<setw(10)<<"sw"<<endl;
                    cout<<setw(4)<<"WORKSTATION"<<setw(19)<<"w"<<endl;
                    cout<<setw(4)<<"STANDARD SERVER"<<setw(15)<<"ss"<<endl;
                    cout<<setw(4)<<"SERVER"<<setw(24)<<"s"<<endl;
    
              do {
                    cout<<"\n You must enter the value from the above table:"<<endl;
    
                    cin>>deviceName_r;
                    deviceName=deviceName_r;
    
                   if (deviceName_r.compare("sw") == 0 || deviceName_r.compare("SW")==0)
                        {
                           cout<<"\n You have selected " << " " <<deviceName_r<<" "<<"-->"<<
                            "\n ************************STANDARD WORKSTATION*************************\n"<<endl;
                        }
                    else if (deviceName_r.compare("w")==0 || deviceName_r.compare("W")==0)
                        {
                            cout<<"\n You have selected "<< " "<<deviceName_r<<" "<<"-->"<<
                            "\n ***************************WORKSTATION******************************* \n"<<endl;
                        }
    
                    else if(deviceName_r.compare("ss")==0 || deviceName_r.compare("SS")==0 )
                        {
                          cout << "\n You have selected "<< " "<<deviceName_r<<" "<<"-->"<<
                          "\n **************************STANDARD SERVER**************************** \n"<<endl;
                        }
    
                     else if(deviceName_r.compare("s") == 0 || deviceName_r.compare("S") == 0)
                        {
                            cout << "\n You have selected "<<" "<< deviceName_r<<" "<<"-->"<<
                            "\n *****************************SERVER********************************** \n"<<endl;
                        }
    
                } while((deviceName_r!="sw") && (deviceName_r!="SW")&&(deviceName_r!="w") &&
                         (deviceName_r!="W")&&(deviceName_r!="ss") && (deviceName_r!="SS")&&
                          (deviceName_r !="s") && (deviceName_r!="S"));
    }
    
    string RiskScore::getDeviceName()
    {
                                    return deviceName;
    }
    
    void RiskScore::setDataClass(int dataClass_sum )
    {
                //dataClass=dataClass_sum;
    			int pii=9; int phi=10; int sysFile=1; int nonPhiPii=2;
    
    			cout<<"\n Data Class"<<setw(20)<<"Value"<<endl;//header
    			cout<<setw(4)<<"PII"<<setw(26)<<pii<<endl;
    			cout<<setw(4)<<"PHI"<<setw(26)<<phi<<endl;
    			cout<<setw(12)<<"SYSTEM FILE"<<setw(18)<<sysFile<<endl;
    			cout<<setw(11)<<"NON PHIPII"<<setw(19)<<nonPhiPii<<endl;
    
    			cout<<"\n Please choose the data class values from above table:"<<endl;
    			cin>>dataClass_sum;
                dataClass=dataClass_sum;
    
    			if(dataClass_sum==pii)
    				{
    					dataClass=dataClass_sum;
    					cout<<"\n This is PII and the system is critical.\n"<<endl;
    					cout<< "\n The value is: "<<" "<<dataClass_sum<<endl;
    
    				}
    			else if(dataClass_sum==phi)
    			    {
    					dataClass=dataClass_sum;
    					cout<<"\n This is PHI and the system is critical.\n"<<endl;
    				}
    			else if (dataClass_sum==sysFile)
    				{
    					dataClass=dataClass_sum;
    					cout<<"\n This data class is System file and it is moderate.\n"<<endl;
    				}
    
    			else if (dataClass_sum==nonPhiPii)
    				{
    					dataClass=dataClass_sum;
    					cout<<"\n This is standard Non-PII or PHI and the system is low.\n"<<endl;
    				}
    }
    
    int RiskScore::getDataClass()
    {
    					return dataClass;
    				}
    
    
    void RiskScore::setDataSpread(int dataSpread_sum)
    {
                    dataSpread = dataSpread_sum;
    
    		    int wiSpread=9, moSpread=3;
    
                    bool right_integers = false;
    
                    cout<<"\n Data Incident Spread "<<setw(30)<<"Value"<<endl;
                    cout<<setw(13)<<"Widely Spread"<<setw(36)<<wiSpread<<endl;
                    cout<<setw(17)<<"Moderately Spread"<<setw(32)<<moSpread<<endl;
    
                    cout<<"\n Please choose the data spread from the table above:"<<endl;
    
                while (!(cin>>dataSpread_sum) )
                    {
                            cin.clear();
                            cin.ignore(numeric_limits<streamsize>::max(),'\n');
                            cout << "Please input one of the numbers in the table above 3 or 9: " << endl;
                    }
    
                while (!right_integers)
                    {
                        if(dataSpread_sum==wiSpread)
                            {
                                right_integers = true;
                                dataSpread=dataSpread_sum;
                                cout<<" This incident is widely spread and the coverage is HIGH:\n"<<endl;
                                cout << "\n The value is:"<<" "<< dataSpread_sum<< endl;
                            }
    
                        else if(dataSpread_sum == moSpread)
                            {
                                dataSpread=dataSpread_sum;
                                right_integers = true;
                                cout<<" This event is moderately spread and the coverage is MODERATE:\n"<<endl;
                            }
    
                        else
                            {
                                cout << "Try input one of the numbers in the table above 3 or 9, thank you!: " << endl;
                                cin>>dataSpread_sum;
                            }
    
                    }
    }
    
    int RiskScore::getDataSpread()
    {
    		return dataSpread;
    }
    
    void RiskScore::setDataPercent(double dataPercent_l)
    {
    
    		this->dataPercent = dataPercent_l;
                double totnum_asset=0.0;
    			double one_twenty=0.2;
    			double twenty1_forty = 0.4;
    			double forty1_sixty=0.6;
    			double sixty1_eighty= 0.8;
    			double eighty1_cent= 1.0;
    
                cout<<"\nPlease enter the total number of data held in the device or locale:\n"<<endl;
                cin>>totnum_asset;
    
    			cout<<"\nThe Percentage Range"<<setw(30)<<"Percentage"<<endl;//header
    			cout<<setw(1)<<"Between 1-20 percent"<<setw(30)<<one_twenty<<endl;
    			cout<<setw(1)<<"Between 21-40 percent"<<setw(29)<<twenty1_forty<<endl;
    			cout<<setw(1)<<"Between 41-60 percent"<<setw(29)<<forty1_sixty<<endl;
    			cout<<setw(1)<<"Between 61-80 percent"<<setw(29)<<sixty1_eighty<<endl;
    			cout<<setw(1)<<"Between 81-100 percent"<<setw(26)<<eighty1_cent<<endl;
    			cout<<"\n Please enter the percentage of data loss from table below.\n"<<endl;
    			cin>>dataPercent_l;
    
    			if(dataPercent_l<=0.2)
    				{
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 20% of the total:\n"<<endl;
    				}
    			else if(dataPercent_l<=0.4)
    			    {
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 40% of the total:\n"<<endl;
    				}
    
                else if(dataPercent_l<=0.6)
    			    {
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 60% of the total:\n"<<endl;
    				}
    			else if(dataPercent_l<=0.8)
    			    {
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 80% of the total:\n"<<endl;
    				}
    
    			else if(dataPercent_l<=1 )
                    {
                        //dataPercent = dataPercent_l;
                        cout<<"The data loss is about 100% of the total:\n"<<endl;
                    }
                else
                  throw invalid_argument("\n You must re-enter in the shown in decimal form e.g.20, .40, .60, .80 and 1");
    }
    
    double RiskScore::getDataPercent()
    {
    		return dataPercent;
    }
    
    void RiskScore::setDataBizuse(int dataBizuse_sum)
    {
                       dataBizuse=dataBizuse_sum;
    					int everyday=9;
    					int often=5;
    					int noncritical=2;
                        bool right_integer = false;
    
    					cout<<"\n Business Use "<<setw(30)<<"Value"<<endl;//header
    					cout<<setw(1)<<"Used on a daily basis"<<setw(22)<<everyday<<endl;
    					cout<<setw(1)<<"Used so often"<<setw(30)<<often<<endl;
    					cout<<setw(1)<<"Used on a rare occasion"<<setw(20)<<noncritical<<endl;
    					cout<<"\n Please choose the business uses by entering the values in table above:\n"<<endl;
    
    					while (!(cin>>dataBizuse_sum))
                                             {
    
                                    cin.clear();
                                    cin.ignore(numeric_limits<streamsize>::max(),'\n');
                                    cout <<"Please input one of the numbers in the table above 2 or 5 or 9:\n " << endl;
                                }
    
    					while (!right_integer)
                                {
    					if(dataBizuse_sum==everyday)
    							{
    								right_integer = true;
    								cout<<" The business use for this machine is daily operations. \n"<<endl;
    							}
    						else if(dataBizuse_sum==often)
    							{
    								right_integer = true;
    								cout<<" The business use for this machine is so often. \n"<<endl;
    							}
    
                            else if(dataBizuse_sum==noncritical)
                                {
                                    right_integer = true;
                                    cout<<" The business use for this machine is rarely (non-critical). \n"<<endl;
                                }
    
                            else
                                {
                                    cout << "Try input one of the numbers in the table above 2 or 5 or 9:\n";
                                    cout<< "\n Thank you! \n" << endl;
                                    cin>>dataBizuse_sum;
                                }
    
                                }
    }
    
     int RiskScore::getDataBizuse()
    {
                        return dataBizuse;
    }
    
    
     void RiskScore::setDataEnviron(int dataEnviron_sum)
    {
                        this->dataEnviron=dataEnviron_sum;
    
                        int prod=9;
    					int stagn=5;
    					int test=2;
    					bool r_integers = false;
    
    					cout<<"\n Environment "<<setw(30)<<"Value"<<endl;//header
    					cout<<setw(1)<<"Used in Production"<<setw(23)<<prod<<endl;
    					cout<<setw(1)<<"Used in Staging"<<setw(26)<<stagn<<endl;
    					cout<<setw(1)<<"Used in Testing"<<setw(26)<<test<<endl;
    					cout<<"\n Please choose the device environment by entering the value from the table:\n"<<endl;
    
    
                    while (!(cin>>dataEnviron_sum))
                        {
                             cin.clear();
                             cin.ignore(numeric_limits<streamsize>::max(),'\n');
                             cout << "Please input one of the numbers in the table above 2 or 5 or 9: " << endl;
                        }
                    while (!r_integers)
                        {
    
    						if(dataEnviron_sum==prod)
    							{
    								r_integers=true;
    								cout<<" This machine is in production environment. \n"<<endl;
    
    							}
    
    						else if(dataEnviron_sum==stagn)
    							{
                                    r_integers=true;
    								cout<<" This machine is in staging environment. \n"<<endl;
    							}
    
                            else if(dataEnviron_sum==test)
                                {
                                    r_integers=true;
                                    cout<<" This machine is in testing environment. \n"<<endl;
                                }
                            else
                                {
                                    cout << "Try input one of the numbers in the table above 2 or 5 or 9:\n";
                                    cout<<"\n Thank you\n" << endl;
                                    cin>>dataEnviron_sum;
                                }
    
                        }
    }
    
    int RiskScore::getDataEnviron()
    {
                        return dataEnviron;
     }
    
     double RiskScore::addCalc()
    {
                        int dataClass_sum;
                        int dataSpread_sum;
                        int dataBizuse_sum;
                        int dataEnviron_sum;
                        double totnum_asset;
                        double dataPercent;
                        double overPercdata =0.0;
    
                        this->sum = dataClass_sum + dataSpread_sum  +  dataBizuse_sum +  dataEnviron_sum;
                        this->overPercdata += totnum_asset * dataPercent;
    
    }
    
    double RiskScore::riskPrior()
    {
                        int dataClass_sum;
                        int dataSpread_sum;
                        int dataBizuse_sum;
                        int dataEnviron_sum;
    
                        sum = dataClass_sum + dataSpread_sum  +  dataBizuse_sum +  dataEnviron_sum;
    
                        if(sum>=1 && sum<=20)
    						{
    							cout<<"This is a risk score of"<<" "<< sum <<" "<< "It is low"<<" "<<"priority P4"<<endl;
                                //int dataClass=dataClass_sum;
    						}
    
                        else if(sum>=21 && sum<=36)
    						{
    							cout<<"This is a risk score of"<<" "<< sum <<" "<< "It is medium"<<" "<<"priority P3"<<endl;
                                dataClass=dataClass_sum;
    						}
    
    					else if(sum>=36 && sum<=46)
    						{
    							cout<<"This is a risk score of"<< sum << "It is high"<<" "<<"priority P2"<<endl;
                                dataClass=dataClass_sum;
    						}
    					else if(sum >= 46)
    						{
    							cout<<"\n This is a risk score of"<<" "<< sum <<" "<< "It is critical"<<" "<<"priority P1\n"<<endl;
                                dataClass=dataClass_sum;
    						}
    }
    
     void RiskScore::print()const
    {
                        cout << "*************************************************************************\n";
                        cout << "************************DHEC RISK SCORE RESULT***************************\n";
                        cout << "*************************************************************************\n";
    					cout << "\n The device name is"<<" "<< deviceName <<" "<<"has a risk score of"<<" "<<sum<<endl;
                        cout << "\n The overall percentage data loss is"<<" "<< overPercdata <<endl;
    
                        string critical="\n*******Red disclosure of restricted information (P1)*******";
    					string high =   "****Orange disclosure of non-restricted information (P2)***";
    					string medium = "**Yellow minimal impact by non-restricted disclosure (P3)**";
    					string low =    "**********Green risk is low as in informational (P4)*******";
    
                        cout<<"\n RISK SCORE NOTIFICATIONS"<<setw(70)<<"RANGE OF RISK SCORE"<<endl;
    					cout<<setw(1)<<critical<<setw(32)<<"greater than 46"<<endl;
    					cout<<setw(1)<<high<<setw(30)<<"Between 36-46"<<endl;
    					cout<<setw(1)<<medium<<setw(30)<<"Between 21-35"<<endl;
    					cout<<setw(1)<<low<<setw(29)<<"Between 1-20"<<endl;
    
    }
    *****************************driver file- main.cpp************************************

    Code:
    #include <iostream>
    #include <iomanip>
    #include "RiskScore.h";
    using namespace std;
    
    
    int main()
    {
                string deviceName;
                int dataClass;
                int dataSpread;
                double dataPercent;
                int dataBizuse;
                int dataEnviron;
                double totnum_asset;
                double overPercdata;
    
                RiskScore riskScore(deviceName,dataClass, dataSpread, dataPercent, dataBizuse, dataEnviron);
                riskScore.instruct();
                riskScore.riskPrior();
                riskScore.getDataClass();
                riskScore.getDataSpread();
                riskScore.getDataPercent();
                riskScore.getDataBizuse();
                riskScore.getDataEnviron();
                riskScore.addCalc();
                riskScore.print();
    
    }
    ***********************************Problem***************************************
    See visual of Output in error.pdf
    Attached Images Attached Images
    Last edited by 2kaud; April 20th, 2017 at 03:48 PM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Guys whye can I sum the score? --class RiskScore

    When posting code, please use code tags so that the code is readable. Before posting, the code needs to be formatted properly. Go Advanced, select the formatted code and click '#'.

    What debugging of the code have you done using the debugger? In cases like this, it is usually necessary to use the debugger to trace through the code and see the execution trace and to watch the value of the various variables to see why the program execution deviates from that expected from the design.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Apr 2017
    Location
    sc
    Posts
    5

    Re: Guys whye can I sum the score? --class RiskScore

    Quote Originally Posted by lokdon View Post
    I make a RiskScore class. Here I made this class re-useable by making them separate like this:

    1. Header// Member function or class definition
    2. Source code or implementation// This where I put how and what the program does.
    3. The driver or main.// This the file that will execute the source code.

    Problems in text:
    My functions does wrong calculations. Please check the error.pdf. I am not sure why the math is wrong.
    Help me figure it out. Thanks.

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    #ifndef    RISKSCORE_H
    #define    RISKSCORE_H
    
    
    //Place a class in a separate file for re-usability
    
    class RiskScore
    	{
    
    	    int dataClass;
            int dataSpread;
    		double dataPercent;
            int dataBizuse;
            int dataEnviron;
            int sum;
            double overPercdata;
            string deviceName;
    
    public:
    		RiskScore(string, int, int, double, int, int ); //it shows all member functions
    		void setDeviceName(string);//name of devices involved
    		string getDeviceName();
    		void setDataClass(int);//data classification
    		int getDataClass();
    		void setDataSpread(int);//how widely the threat spread
    		int getDataSpread();
    		void setDataPercent(double);//percentage of data under risk
    		double getDataPercent();
    		void setDataBizuse(int);//highly, often and rarely used
    		int getDataBizuse();
    		void setDataEnviron(int);//environment in which data is used P/stage/T
    		int getDataEnviron();
            double riskPrior();//Calculate all attributes of the Risk score per device
    		void print()const;
    		double addCalc();//total sum up of the scores
    		void instruct();
    
    private:
    };
    
    #endif
    ****************************source code**************************************
    Code:
    #include <limits>
    #include <iostream>
    #include <stdexcept>
    #include <iomanip>
    #include "RiskScore.h";
    using namespace std;
    
    RiskScore::RiskScore(string deviceName_r,int dataClass_sum, int dataSpread_sum, double dataPercent_l, int dataBizuse_sum, int dataEnviron_sum)
    	{
    		setDeviceName(deviceName_r);//validation and store of device name
    		setDataClass(dataClass_sum);//validation and store of data class
    		setDataSpread(dataSpread_sum);//validation and store data incident spread
    		setDataPercent(dataPercent_l);//validation and store of device data percentage
    		setDataBizuse(dataBizuse_sum);//validation and store of device BIZ use
            setDataEnviron(dataEnviron_sum);//validation and store of device environment
    }
    
    void RiskScore::instruct()//program guide and detail
    {
                    cout << " This program is to help the department obtain the risk scores \n"<<endl;
                    cout << " for all security incident. In turn the department can use this \n"<<endl;
                    cout << " to tally up the financial lose that comes with the incidents. \n"<<endl;
                    cout << " This will help the department with budgeting for IT security. \n "<<endl;
    }
    
    void RiskScore::setDeviceName(string deviceName_r )
    {
                    deviceName=deviceName_r;
                    cout<<"\n Device Name"<<setw(20)<<"Value"<<endl;//header
                    cout<<setw(4)<<"STANDARD WORKSTATION"<<setw(10)<<"sw"<<endl;
                    cout<<setw(4)<<"WORKSTATION"<<setw(19)<<"w"<<endl;
                    cout<<setw(4)<<"STANDARD SERVER"<<setw(15)<<"ss"<<endl;
                    cout<<setw(4)<<"SERVER"<<setw(24)<<"s"<<endl;
    
              do {
                    cout<<"\n You must enter the value from the above table:"<<endl;
    
                    cin>>deviceName_r;
                    deviceName=deviceName_r;
    
                   if (deviceName_r.compare("sw") == 0 || deviceName_r.compare("SW")==0)
                        {
                           cout<<"\n You have selected " << " " <<deviceName_r<<" "<<"-->"<<
                            "\n ************************STANDARD WORKSTATION*************************\n"<<endl;
                        }
                    else if (deviceName_r.compare("w")==0 || deviceName_r.compare("W")==0)
                        {
                            cout<<"\n You have selected "<< " "<<deviceName_r<<" "<<"-->"<<
                            "\n ***************************WORKSTATION******************************* \n"<<endl;
                        }
    
                    else if(deviceName_r.compare("ss")==0 || deviceName_r.compare("SS")==0 )
                        {
                          cout << "\n You have selected "<< " "<<deviceName_r<<" "<<"-->"<<
                          "\n **************************STANDARD SERVER**************************** \n"<<endl;
                        }
    
                     else if(deviceName_r.compare("s") == 0 || deviceName_r.compare("S") == 0)
                        {
                            cout << "\n You have selected "<<" "<< deviceName_r<<" "<<"-->"<<
                            "\n *****************************SERVER********************************** \n"<<endl;
                        }
    
                } while((deviceName_r!="sw") && (deviceName_r!="SW")&&(deviceName_r!="w") &&
                         (deviceName_r!="W")&&(deviceName_r!="ss") && (deviceName_r!="SS")&&
                          (deviceName_r !="s") && (deviceName_r!="S"));
    }
    
    string RiskScore::getDeviceName()
    {
                                    return deviceName;
    }
    
    void RiskScore::setDataClass(int dataClass_sum )
    {
                //dataClass=dataClass_sum;
    			int pii=9; int phi=10; int sysFile=1; int nonPhiPii=2;
    
    			cout<<"\n Data Class"<<setw(20)<<"Value"<<endl;//header
    			cout<<setw(4)<<"PII"<<setw(26)<<pii<<endl;
    			cout<<setw(4)<<"PHI"<<setw(26)<<phi<<endl;
    			cout<<setw(12)<<"SYSTEM FILE"<<setw(18)<<sysFile<<endl;
    			cout<<setw(11)<<"NON PHIPII"<<setw(19)<<nonPhiPii<<endl;
    
    			cout<<"\n Please choose the data class values from above table:"<<endl;
    			cin>>dataClass_sum;
                dataClass=dataClass_sum;
    
    			if(dataClass_sum==pii)
    				{
    					dataClass=dataClass_sum;
    					cout<<"\n This is PII and the system is critical.\n"<<endl;
    					cout<< "\n The value is: "<<" "<<dataClass_sum<<endl;
    
    				}
    			else if(dataClass_sum==phi)
    			    {
    					dataClass=dataClass_sum;
    					cout<<"\n This is PHI and the system is critical.\n"<<endl;
    				}
    			else if (dataClass_sum==sysFile)
    				{
    					dataClass=dataClass_sum;
    					cout<<"\n This data class is System file and it is moderate.\n"<<endl;
    				}
    
    			else if (dataClass_sum==nonPhiPii)
    				{
    					dataClass=dataClass_sum;
    					cout<<"\n This is standard Non-PII or PHI and the system is low.\n"<<endl;
    				}
    }
    
    int RiskScore::getDataClass()
    {
    					return dataClass;
    				}
    
    
    void RiskScore::setDataSpread(int dataSpread_sum)
    {
                    dataSpread = dataSpread_sum;
    
    		    int wiSpread=9, moSpread=3;
    
                    bool right_integers = false;
    
                    cout<<"\n Data Incident Spread "<<setw(30)<<"Value"<<endl;
                    cout<<setw(13)<<"Widely Spread"<<setw(36)<<wiSpread<<endl;
                    cout<<setw(17)<<"Moderately Spread"<<setw(32)<<moSpread<<endl;
    
                    cout<<"\n Please choose the data spread from the table above:"<<endl;
    
                while (!(cin>>dataSpread_sum) )
                    {
                            cin.clear();
                            cin.ignore(numeric_limits<streamsize>::max(),'\n');
                            cout << "Please input one of the numbers in the table above 3 or 9: " << endl;
                    }
    
                while (!right_integers)
                    {
                        if(dataSpread_sum==wiSpread)
                            {
                                right_integers = true;
                                dataSpread=dataSpread_sum;
                                cout<<" This incident is widely spread and the coverage is HIGH:\n"<<endl;
                                cout << "\n The value is:"<<" "<< dataSpread_sum<< endl;
                            }
    
                        else if(dataSpread_sum == moSpread)
                            {
                                dataSpread=dataSpread_sum;
                                right_integers = true;
                                cout<<" This event is moderately spread and the coverage is MODERATE:\n"<<endl;
                            }
    
                        else
                            {
                                cout << "Try input one of the numbers in the table above 3 or 9, thank you!: " << endl;
                                cin>>dataSpread_sum;
                            }
    
                    }
    }
    
    int RiskScore::getDataSpread()
    {
    		return dataSpread;
    }
    
    void RiskScore::setDataPercent(double dataPercent_l)
    {
    
    		this->dataPercent = dataPercent_l;
                double totnum_asset=0.0;
    			double one_twenty=0.2;
    			double twenty1_forty = 0.4;
    			double forty1_sixty=0.6;
    			double sixty1_eighty= 0.8;
    			double eighty1_cent= 1.0;
    
                cout<<"\nPlease enter the total number of data held in the device or locale:\n"<<endl;
                cin>>totnum_asset;
    
    			cout<<"\nThe Percentage Range"<<setw(30)<<"Percentage"<<endl;//header
    			cout<<setw(1)<<"Between 1-20 percent"<<setw(30)<<one_twenty<<endl;
    			cout<<setw(1)<<"Between 21-40 percent"<<setw(29)<<twenty1_forty<<endl;
    			cout<<setw(1)<<"Between 41-60 percent"<<setw(29)<<forty1_sixty<<endl;
    			cout<<setw(1)<<"Between 61-80 percent"<<setw(29)<<sixty1_eighty<<endl;
    			cout<<setw(1)<<"Between 81-100 percent"<<setw(26)<<eighty1_cent<<endl;
    			cout<<"\n Please enter the percentage of data loss from table below.\n"<<endl;
    			cin>>dataPercent_l;
    
    			if(dataPercent_l<=0.2)
    				{
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 20% of the total:\n"<<endl;
    				}
    			else if(dataPercent_l<=0.4)
    			    {
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 40% of the total:\n"<<endl;
    				}
    
                else if(dataPercent_l<=0.6)
    			    {
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 60% of the total:\n"<<endl;
    				}
    			else if(dataPercent_l<=0.8)
    			    {
    					//dataPercent = dataPercent_l;
    					cout<<" The data loss is about 80% of the total:\n"<<endl;
    				}
    
    			else if(dataPercent_l<=1 )
                    {
                        //dataPercent = dataPercent_l;
                        cout<<"The data loss is about 100% of the total:\n"<<endl;
                    }
                else
                  throw invalid_argument("\n You must re-enter in the shown in decimal form e.g.20, .40, .60, .80 and 1");
    }
    
    double RiskScore::getDataPercent()
    {
    		return dataPercent;
    }
    
    void RiskScore::setDataBizuse(int dataBizuse_sum)
    {
                       dataBizuse=dataBizuse_sum;
    					int everyday=9;
    					int often=5;
    					int noncritical=2;
                        bool right_integer = false;
    
    					cout<<"\n Business Use "<<setw(30)<<"Value"<<endl;//header
    					cout<<setw(1)<<"Used on a daily basis"<<setw(22)<<everyday<<endl;
    					cout<<setw(1)<<"Used so often"<<setw(30)<<often<<endl;
    					cout<<setw(1)<<"Used on a rare occasion"<<setw(20)<<noncritical<<endl;
    					cout<<"\n Please choose the business uses by entering the values in table above:\n"<<endl;
    
    					while (!(cin>>dataBizuse_sum))
                                             {
    
                                    cin.clear();
                                    cin.ignore(numeric_limits<streamsize>::max(),'\n');
                                    cout <<"Please input one of the numbers in the table above 2 or 5 or 9:\n " << endl;
                                }
    
    					while (!right_integer)
                                {
    					if(dataBizuse_sum==everyday)
    							{
    								right_integer = true;
    								cout<<" The business use for this machine is daily operations. \n"<<endl;
    							}
    						else if(dataBizuse_sum==often)
    							{
    								right_integer = true;
    								cout<<" The business use for this machine is so often. \n"<<endl;
    							}
    
                            else if(dataBizuse_sum==noncritical)
                                {
                                    right_integer = true;
                                    cout<<" The business use for this machine is rarely (non-critical). \n"<<endl;
                                }
    
                            else
                                {
                                    cout << "Try input one of the numbers in the table above 2 or 5 or 9:\n";
                                    cout<< "\n Thank you! \n" << endl;
                                    cin>>dataBizuse_sum;
                                }
    
                                }
    }
    
     int RiskScore::getDataBizuse()
    {
                        return dataBizuse;
    }
    
    
     void RiskScore::setDataEnviron(int dataEnviron_sum)
    {
                        this->dataEnviron=dataEnviron_sum;
    
                        int prod=9;
    					int stagn=5;
    					int test=2;
    					bool r_integers = false;
    
    					cout<<"\n Environment "<<setw(30)<<"Value"<<endl;//header
    					cout<<setw(1)<<"Used in Production"<<setw(23)<<prod<<endl;
    					cout<<setw(1)<<"Used in Staging"<<setw(26)<<stagn<<endl;
    					cout<<setw(1)<<"Used in Testing"<<setw(26)<<test<<endl;
    					cout<<"\n Please choose the device environment by entering the value from the table:\n"<<endl;
    
    
                    while (!(cin>>dataEnviron_sum))
                        {
                             cin.clear();
                             cin.ignore(numeric_limits<streamsize>::max(),'\n');
                             cout << "Please input one of the numbers in the table above 2 or 5 or 9: " << endl;
                        }
                    while (!r_integers)
                        {
    
    						if(dataEnviron_sum==prod)
    							{
    								r_integers=true;
    								cout<<" This machine is in production environment. \n"<<endl;
    
    							}
    
    						else if(dataEnviron_sum==stagn)
    							{
                                    r_integers=true;
    								cout<<" This machine is in staging environment. \n"<<endl;
    							}
    
                            else if(dataEnviron_sum==test)
                                {
                                    r_integers=true;
                                    cout<<" This machine is in testing environment. \n"<<endl;
                                }
                            else
                                {
                                    cout << "Try input one of the numbers in the table above 2 or 5 or 9:\n";
                                    cout<<"\n Thank you\n" << endl;
                                    cin>>dataEnviron_sum;
                                }
    
                        }
    }
    
    int RiskScore::getDataEnviron()
    {
                        return dataEnviron;
     }
    
     double RiskScore::addCalc()
    {
                        int dataClass_sum;
                        int dataSpread_sum;
                        int dataBizuse_sum;
                        int dataEnviron_sum;
                        double totnum_asset;
                        double dataPercent;
                        double overPercdata =0.0;
    
                        this->sum = dataClass_sum + dataSpread_sum  +  dataBizuse_sum +  dataEnviron_sum;
                        this->overPercdata += totnum_asset * dataPercent;
    
    }
    
    double RiskScore::riskPrior()
    {
                        int dataClass_sum;
                        int dataSpread_sum;
                        int dataBizuse_sum;
                        int dataEnviron_sum;
    
                        sum = dataClass_sum + dataSpread_sum  +  dataBizuse_sum +  dataEnviron_sum;
    
                        if(sum>=1 && sum<=20)
    						{
    							cout<<"This is a risk score of"<<" "<< sum <<" "<< "It is low"<<" "<<"priority P4"<<endl;
                                //int dataClass=dataClass_sum;
    						}
    
                        else if(sum>=21 && sum<=36)
    						{
    							cout<<"This is a risk score of"<<" "<< sum <<" "<< "It is medium"<<" "<<"priority P3"<<endl;
                                dataClass=dataClass_sum;
    						}
    
    					else if(sum>=36 && sum<=46)
    						{
    							cout<<"This is a risk score of"<< sum << "It is high"<<" "<<"priority P2"<<endl;
                                dataClass=dataClass_sum;
    						}
    					else if(sum >= 46)
    						{
    							cout<<"\n This is a risk score of"<<" "<< sum <<" "<< "It is critical"<<" "<<"priority P1\n"<<endl;
                                dataClass=dataClass_sum;
    						}
    }
    
     void RiskScore::print()const
    {
                        cout << "*************************************************************************\n";
                        cout << "************************DHEC RISK SCORE RESULT***************************\n";
                        cout << "*************************************************************************\n";
    					cout << "\n The device name is"<<" "<< deviceName <<" "<<"has a risk score of"<<" "<<sum<<endl;
                        cout << "\n The overall percentage data loss is"<<" "<< overPercdata <<endl;
    
                        string critical="\n*******Red disclosure of restricted information (P1)*******";
    					string high =   "****Orange disclosure of non-restricted information (P2)***";
    					string medium = "**Yellow minimal impact by non-restricted disclosure (P3)**";
    					string low =    "**********Green risk is low as in informational (P4)*******";
    
                        cout<<"\n RISK SCORE NOTIFICATIONS"<<setw(70)<<"RANGE OF RISK SCORE"<<endl;
    					cout<<setw(1)<<critical<<setw(32)<<"greater than 46"<<endl;
    					cout<<setw(1)<<high<<setw(30)<<"Between 36-46"<<endl;
    					cout<<setw(1)<<medium<<setw(30)<<"Between 21-35"<<endl;
    					cout<<setw(1)<<low<<setw(29)<<"Between 1-20"<<endl;
    
    }
    *****************************driver file- main.cpp************************************

    Code:
    #include <iostream>
    #include <iomanip>
    #include "RiskScore.h";
    using namespace std;
    
    
    int main()
    {
                string deviceName;
                int dataClass;
                int dataSpread;
                double dataPercent;
                int dataBizuse;
                int dataEnviron;
                double totnum_asset;
                double overPercdata;
    
                RiskScore riskScore(deviceName,dataClass, dataSpread, dataPercent, dataBizuse, dataEnviron);
                riskScore.instruct();
                riskScore.riskPrior();
                riskScore.getDataClass();
                riskScore.getDataSpread();
                riskScore.getDataPercent();
                riskScore.getDataBizuse();
                riskScore.getDataEnviron();
                riskScore.addCalc();
                riskScore.print();
    
    }
    ***********************************Problem***************************************
    See visual of Output in error.pdf
    Thanks

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Guys whye can I sum the score? --class RiskScore

    My functions does wrong calculations
    You don't seem to initialise member variables as part of the class constructor. It is considered good practice that member variables are initialised to a known value in the class constructor(s). Using uninitialised class variables is a common source of 'wrong' values.

    Where the value given to a variable doesn't change, it is recommended that these are defined as const so that any changes to these values tried is flagged by the compiler.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 2017
    Location
    sc
    Posts
    5

    Re: Guys whye can I sum the score? --class RiskScore

    Quote Originally Posted by 2kaud View Post
    You don't seem to initialise member variables as part of the class constructor. It is considered good practice that member variables are initialised to a known value in the class constructor(s). Using uninitialised class variables is a common source of 'wrong' values.

    Where the value given to a variable doesn't change, it is recommended that these are defined as const so that any changes to these values tried is flagged by the compiler.

    Guys thanks for your help I did solve the problem by way of debugging and code sanitization thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured