mester Programming Projec This program should illustrate and simulate the ethica
ID: 3856718 • Letter: M
Question
mester Programming Projec This program should illustrate and simulate the ethical issue of the tragedy of the commons. In essence, it is a software toy that permits users to examine the balance between choices that benefit the individual but cost society versus those that benefit society at a cost to the individual The program can be written in either Java or C. Students have broad discretion with regards to implementation. Quick overview Please consider creating an array (or linked list)of objects. Each object might have an integer ID, a Boolean switch (selfish or not-selfish), and a happiness score (integer). Then use the object in part A Finally, implement part B representing the society Part A. The first part of the program will create a series of individuals (objects) who make decision that are either selfish or altruistic. Each object will make its decisions independently. Some objects may choose to always be selfish. Others will always be altruistic. And some might be random. Each object will have an identity (an integer is sufficient), and can generate its choice. Each object will also have a score for happiness, which can change The program should be able to create from 1 to 20 (or more, if you prefer) individuals according to the user's preference The program should be able to run multiple iterations (each with the same individuals), and be capable of up to 20 (or more, if you prefer) iterations, with output for each iteration. When an individual is selfish, they gain 5 happiness points. When they are altruistic, they lose 2 happiness points When Part B is done, the government score will be added to the functionality of Part A. Part B. The second part will incorporate an entity called "government", which will represent the aggregate effects of individual decisions by the individual objects. If all individuals choose to be altruistic, society will benefit, but all of the individuals will be poor. If all individuals choose to be selfish, the individuals may do well, but society will be miserable. And if some number of individuals are altruistic and others are selfish, a balance might be achieved. The balance could be optimized, providing results for the number of objects with various characteristics. If there are more selfish individuals than altruistic individuals, the government score is a negative number equal to the net number of selfish individuals (selfish - altruistic) If there are an equal number of selfish and altruistic individuals, the government score is a zero If there are more altruistic individuals than selfish individuals, the government score is a positive number equal to the net number of altruistic individuals. (Altruistic-selfish).Explanation / Answer
#include<stdio.h>
#include<stdbool.h>
typedef struct obj
{
int ID;
bool Selfish_or_not;
int happiness_score;
}Obj;
int main()
{
int i,govt_score,No_of_selfish,No_of_altruistic;
Obj arr[20];
//Part A
//Entering individual details
printf("Enter Id,selfish or not, happiness score respectively ");
for(i=0;i<20;i++)
{
scanf("%d%d%d",&arr[i].ID,&arr[i].Selfish_or_not,&arr[i].happiness_score);
}
//Displaying
printf("Displaying Id selfish_or_not happiness score ");
for(i=0;i<20;i++)
{
printf("%d %d %d ",arr[i].ID,arr[i].Selfish_or_not,arr[i].happiness_score);
}
//adding happiness score to the individuals
for(i=0;i<20;i++)
{
//if the individual is selfish
//then add 5 points to that individual
if(arr[i].Selfish_or_not)
arr[i].happiness_score+=5;
//if the individual is not selfish (altruistic)
//then remove 2 points from that indivisual
else
arr[i].happiness_score-=2;
}
printf(" ");
//Displaying
printf("Displaying after score added Id selfish_or_not happiness score ");
for(i=0;i<20;i++)
{
printf("%d %d %d ",arr[i].ID,arr[i].Selfish_or_not,arr[i].happiness_score);
}
//Part B
//counting number of selfish individuals and altruistics individuals
No_of_selfish=0;
No_of_altruistic=0;
for(i=0;i<20;i++)
{
if(arr[i].Selfish_or_not)
No_of_selfish++;
else
No_of_altruistic++;
}
//if more selfish individuals are more than altruistic individuals
//then the govt score is Negative
if(No_of_selfish>No_of_altruistic)
{
//govt score will be Negative
govt_score=No_of_altruistic-No_of_selfish;
}
//if more altruistic individuals are more than selfish individuals
//then the govt score is positive
if(No_of_selfish<No_of_altruistic)
{
//govt score will be Positive
govt_score=No_of_altruistic-No_of_selfish;
}
//if both are equal
//then govt score is 0
else
govt_score=0;
//adding govt score to all the individuals
for(i=0;i<20;i++)
{
arr[i].Selfish_or_not+=govt_score;
}
//Now giving punishment to every individual
for(i=0;i<20;i++)
{
//if an individual is selfish AND govt score is Positive
if(arr[i].Selfish_or_not)
{
if(govt_score>0)
printf("%d will get 10 percentage chances of punishment And the penality is 50 points ",arr[i].ID);
}
else
{
printf("%d will get 50 percentage chances of punishment And the penality is 75 points ",arr[i].ID);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.