סדנא תרגיל 1 שאלה 2

bennyסדנא ב++C, תרגילים בסדנא ב++CLeave a Comment

חישוב משכורת של עובד – סדנא ב ++C תרגיל 1 שאלה 2


/******************************

lecturer: david Cohen
discription: chack who get the highes salary. & who worked max hours

*******************************/
#include "workers.h"


int main()
{
	cout << "enter details, to end enter 0\n"; int id; char name[21]; float salery; int hours; int mor_hours; Workers A,B,C; float mascoret=0; // to save the highest salary. int shaot=0; //// to save the highest hours. while (1) { cin >> id;
		if (id==0)
		{
			break;
		}
		else
		{
			A.set_id(id);
		}
		cin >> name;      A.set_name(name);
		cin >> salery;    A.set_salery(salery);
		cin >> hours;     A.set_hours(hours);
		cin >> mor_hours; A.set_mor_hours(mor_hours);

		if (id<0||hours<0||mor_hours<0||salery<0)           // input loop.
		{
			cout << "ERROR" << endl; continue; } if (A.clculate_salery()>mascoret)   // if is salary biger then  mascoret
		{
			mascoret = A.clculate_salery();   // update the highest mascoret value.
			B = A; // save the detiles information of  tihs person (my be wil need to print his ditales).
		}
		
	
		if (A.get_hours() + A.get_mor_hours()>shaot)     // if is hours biger then shaot
		{
			shaot = A.get_hours() + A.get_mor_hours();    // update the highest shaot value
			C = A;      // save the detiles information of  tihs person (my be wil need to print his ditales).
		}
		

	
	}


	cout << "highest salary:" << B.get_id() <<" "<< B.get_name() << endl;
	cout << "hardest worker:" << C.get_id() << " " << C.get_name() << endl;




	//system("pause");

	return 0;
}
/******************************

enter details, to end enter 0
123456789	avraham 	50	40	2
135792468	yaakov		100	30	0
975312468	sara	30	45	10
0
highest salary: 	135792468	yaakov	
hardest worker: 	975312468	sara


*******************************/




#include "workers.h"




void Workers::set_id(int my_id)
{
	id = my_id;
}
int Workers::get_id(){ return id; }

void Workers::set_name(char * str)
{
	strcpy(name, str);
}
char* Workers::get_name(){ return name; }

void Workers::set_salery(float x)
{
	salery = x;
}
float Workers::get_salery(){ return salery; }

void Workers::set_hours(int h)
{
	hours = h;
}
int Workers::get_hours(){ return hours; }

void Workers::set_mor_hours(int mh)
{
	mor_hours = mh;
}
int Workers::get_mor_hours(){ return mor_hours; }

float Workers::clculate_salery()
{
float sum;
sum = (float)hours*salery + (float)mor_hours*(1.5*salery);
return sum;
}



Workers::~Workers()
{
}



#pragma once

#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;

class Workers
{
private:
	int id;
	char name[21];
	float salery;
	int hours;
	int mor_hours;
public:
	
//	Workers();
	void set_id(int);
	int get_id(); 
	void set_name(char*);
	char*get_name();
	void set_salery(float);
	float get_salery();
	void set_hours(int);
	int get_hours();
	void set_mor_hours(int);
	int get_mor_hours();
	float clculate_salery();
	
	~Workers();
};


נכתב ע"י benny

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *