0% found this document useful (0 votes)
43 views4 pages

Comp Assigment PDF

The document contains code for three C++ classes - HumanResourceDepartment, FinanceDepartment, and PayrollDepartment. The HumanResourceDepartment and FinanceDepartment classes get and display customer details like name, age, account number, salary, income tax. The PayrollDepartment class inherits from these and calculates the net salary by subtracting income tax from salary. The main function creates objects of these classes, gets the input, displays output, and finds the net salary.

Uploaded by

THATO TSILE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Comp Assigment PDF

The document contains code for three C++ classes - HumanResourceDepartment, FinanceDepartment, and PayrollDepartment. The HumanResourceDepartment and FinanceDepartment classes get and display customer details like name, age, account number, salary, income tax. The PayrollDepartment class inherits from these and calculates the net salary by subtracting income tax from salary. The main function creates objects of these classes, gets the input, displays output, and finds the net salary.

Uploaded by

THATO TSILE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Thato Kagelo Tsile

ID:22000007
Mechatronics and Industrial
Instrumentation
Code 1
#include <iostream>
#include <string>
using namespace std;

class HumanResourceDepartment { // class for human resource department


public:

string CustomerName;
int CustomerAge;
int CustomerAccNum;

void gethumanresource() { // function to get customer details for human


resource department
cout << "Enter customer name" << endl;
cin >> CustomerName;
cout << "Enter customer age" << endl;
cin >> CustomerAge;
cout << "Enter customer account number " << endl;
cin >> CustomerAccNum;
if (CustomerAccNum < 10000000 && CustomerAccNum > 99999999) {
cout << "Please enter an 8 digit account number" << endl;
cin >> CustomerAccNum;

}
}
void showhumanresource() { // function to show customer details for customer
details
cout << "Customer Name : " << CustomerName << endl;
cout << "Customer Age : " << CustomerAge << endl;
cout << "Customer Account Number : " << CustomerAccNum << endl;
}
};
class FinanceDepartment { // class for finance department
public :
float CustomerSalary;
int CustomerIncomeTax;

void getfinance() { // function to get customer details for finance


department
cout << "Enter customer salary " << endl;
cin >> CustomerSalary;
cout << "Enter customer income tax " << endl;
cin >> CustomerIncomeTax;

if (CustomerIncomeTax < 1 && CustomerIncomeTax>100) {


cout << "Please enter a number between 1 and 100" << endl;
cin >> CustomerIncomeTax;
}
}
void showfinance() { // function to show customer details for finance
department
cout << "Customer Salary " << CustomerSalary << endl;
cout << "Customer Income Tax " << CustomerIncomeTax << endl;
}
};
class PayrollDepartment : public HumanResourceDepartment, public
FinanceDepartment // class for payroll department which inherits properties from
human resource department
{

public:

float NetSalary ;
void findnetsalary() {// funtion to calculate net salary
NetSalary = CustomerSalary * (CustomerIncomeTax /100) ;
cout << "Customer Net Salary is : " << NetSalary << endl;
}

};
int main()
{
HumanResourceDepartment HR; // creating object from human resource
department class
FinanceDepartment FD ;// creating object from finance department class
PayrollDepartment PD ;// creating object from payroll department class
HR.gethumanresource();
HR.showhumanresource();

FD.getfinance();
FD.showfinance();

PD.findnetsalary();

return 0;

}
Code 2
#include <iostream>
#include<string>
#include<fstream>
#include<vector>
#include<map>
#include<iterator>

using namespace std;

int main()
{

map<string, int>WordFrequency; // making a map for word frequency


string MaxWord; //creating variable to store maximum number of words
int NumWords; // creating variable to store word charecters
NumWords = 0;

ifstream myfile; // function reads contents of file


myfile.open("notes.txt");
vector<string>FileContents((istream_iterator<string>(myfile)),
istream_iterator<string>()); // vector created
myfile.close();// file is closed

for (int i = 0;i < FileContents.size();i++)


{
WordFrequency[FileContents[i]]++;
if (WordFrequency[FileContents[i]] > NumWords)
{
NumWords = WordFrequency[FileContents[i]];
MaxWord = FileContents[i];
}
}

cout << "The word that appears most is : " << MaxWord << endl;
cout << MaxWord << " appears : " << NumWords << " times"<< endl;
cout << "Number of characters : " << MaxWord << " has " <<
MaxWord.length() << " characters" << endl;
for (int i = 0;i < MaxWord.length();i++)// converts lowwer case letters to
upper case letters
{
MaxWord[i] = toupper(MaxWord[i]);
}

cout << "Word in ALL CAPS : " << MaxWord << endl;
cout << "Total number of words in the file : " << FileContents.size() <<
endl;

return 0;

You might also like