Jump to content

All my products and services are free. All my costs are met by donations I receive from my users. If you enjoy using any of my products, please donate to support me. My bare hosting costs are currently not met so please consider donating by either clicking this text or the Patreon link on the right.

Patreon

Recommended Posts

Posted

So hey everyone. Hope all is well. :)

This is way off topic, but I figure there's a few programmers who hang here that could help me to understand this a bit better. I'm taking a Programming Logic class, and I think I'm in over my head. I was hoping someone could help me with some very basic skills and tell me what I'm spacing out here. Thanks in advance for your help everyone!

Create an application in which you create an array of 20 Employee objects. In turn, pass each Employee object to a method that accepts an Employee, prompts the user for necessary data, and returns a "filled" Employee object to the array.

Pass the Employee array to a method that counts the number of Employees in each of the 10 job description categories and displays a count of each.

Pass the Employee array to a method that counts the number in each of the two insurance plans and displays a count of each.

Pass the Employee array to a method that sorts the Employees in ascending ID number order and display a list of the first and last names of the Employees in ID number order.

I think I need to employ a Bubble Sort, which is horribly inefficient but easier to understand. Not sure.

If you're feeling brave, here's the next part of my assignment. Try your hand at that. ;)

Create an application that continues to prompt the user for Employee data and writes the data to a file; the application continues until the user enters a 0 for an ID number to indicate the desire to quit. While the ID number is not zero, prompt the user for a value for each Employee field and assign it to an Employee object, except DO NOT prompt for city, state, job title, or hourly pay rate.

Any time the user enters an invalid field value, continue to reprompt the user for the same data. Only when a data item is valid, assign it to the appropriate field. Invalid field values are:

  • An employee ID number that is greater than 999
  • A ZIP code that is not in a list of allowed ZIP codes
  • A job description that is not between 10 and 19 inclusive
  • An insurance plan code that is not 1 or 2

If this sounds like it's too complicated, I'll gladly show you what I have but I have a feeling what I have is completely wrong. :(

Thanks!

Posted
So hey everyone. Hope all is well. :)

This is way off topic, but I figure there's a few programmers who hang here that could help me to understand this a bit better. I'm taking a Programming Logic class, and I think I'm in over my head. I was hoping someone could help me with some very basic skills and tell me what I'm spacing out here. Thanks in advance for your help everyone!

I think I need to employ a Bubble Sort, which is horribly inefficient but easier to understand. Not sure.

If you're feeling brave, here's the next part of my assignment. Try your hand at that. ;)

If this sounds like it's too complicated, I'll gladly show you what I have but I have a feeling what I have is completely wrong. :(

Thanks!

i dont know anything about logic

ive done c++

and visuall basic

but it sounds like a simple program if you understand what is written (i dont but im drunk lol)

i'll take another look in morning

the 1 think ive learned from programming is that there all very similer in code,

basicly i know this dont help but i do understand how hard it is to understand written instructions,

i had to make a simple paintshop program,but written on paper made me think they wanted paintshop pro,

well im off to bed

Posted

I think Adultery means the class is called "Programming Logic" meaning the class is all about the logic. More of a pseudocode, wrap your head around the problem course. I don't know what language you are using in particular, but that would be helpful.

Posted

Hi!

Yeah, I'm working on the logic, tables and pseudocode. The logic is supposed to be the easy part! Haha! Supposedly it's more technoque than the actual compiling. My last unit assignment was easier. For example:

private numeric contractNumber
private numeric customerIDNumber
private numeric vehicleIdentificationNumber
private numeric startMonth
private numeric startDay
private numeric startYear
private numeric agreementLength
private numeric endMonth
private numeric endDay
private numeric endYear
private string insuranceIndicator

public numeric getContractNumber()
return contractNumber

public numeric getCustomerIDNumber()
return customerIDNumber

public numeric getVehicleIdentificationNumber()
return vehicleIdentificationNumber

public numeric getStartMonth()
return startMonth

public numeric getStartDay()
return startDay

public numeric getStartYear()
return startYear

public numeric getAgreementLength()
return agreementLength

public numeric getEndMonth()
return endMonth

public numeric getEndDay()
return endDay

public numeric getEndYear()
return endYear

public string getInsuranceIndicator()
return insuranceIndicator

public void setContractNumber(numeric number)
if number < 10000 OR number > 99999
print â??Error message: Invalid contract numberâ?
else
contractNumber = number
endif
return

public void setCustomerIDNumber(numeric number)
if number < 100 OR number > 999
print â??Error message: Invalid ID numberâ?
else
customerIDNumber = number
endif
return

public void setVehicleIdentificationNumber(numeric number)
if number < 100 OR number > 999
print â??Error message: Invalid vehicle identification numberâ?
else
vehicleIdentificationNumber = number
endif
return

public void setStartingDate(numeric month, numeric day, numeric year)
numeric todayMonth = this month
numeric todayDay = this day
numeric todayYear = this year

if year = todayYear AND (month < todayMonth
OR (month = todayMonth AND day < todayDay)) OR year < todayYear
print â??Error message: Invalid starting dateâ?
else
if day < 1 OR day > 31 OR (month = 2 AND day > 28)
OR ((month = 9 OR month = 4 OR month = 6
OR month = 11) AND day > 30)
print â??Error message: Invalid starting dateâ?
startDay = 0
startMonth = 0
startYear = 0
else
startDay = day
startMonth = month
startYear = year
endif
endif
return

public void setAgreementLength(int days)
if days < 1 OR days > 30
print â??Error message: Invalid agreement lengthâ?
else
endDay = startDay + days
endMonth = startMonth
endYear = startYear

if (endDay > 31 AND (startMonth = 1 OR startMonth = 3
OR startMonth = 5 OR startMonth = 7 OR startMonth = 8
OR startMonth = 10 OR startMonth = 12))
endDay = endDay - 31
if (startMonth = 12)
endMonth = 1
endYear = startYear + 1
else
endMonth = startMonth + 1
endif
else
if (endDay > 30 AND (startMonth = 4 OR startMonth = 6
OR startMonth = 9 OR startMonth = 11))
endDay = endDay - 30
endMonth = startMonth + 1
else
if (endDay > 28 AND startMonth = 2)
endDay = endDay - 28
endMonth = startMonth + 1
endif
endif
endif
endif
return

public void setInsuranceIndicator(string insuranceIndicator)
if insuranceIndicator not equal â??Yâ? OR insuranceIndicator not equal â??Nâ?
print â??Error message: Invalid indicatorâ?
else
this.insuranceIndicator = insuranceIndicator
endif
return
endClass

Posted

Ok, so you are using c++ then. Yeah, I don't have much experience with that one. I'm primarily a script programmer (vba, vbscript, AHK, etc.), but I do have C and FORTRAN in my background too. I'm sorta learning Python (mainly as I need to work with it). I could probably help with pseudocode, but not much on the code. Perhaps someone that knows c++ could help?

EDIT: Upon review, that's not exactly c++ either. I guess you are doing some kind of simplified logic only, no formatting c++ variant? Or, is that c#? In any case, I can't help with formatting!

Posted

It's incredibly off topic asking help for your homework on here lol But since your a nice guy I'll oblige you in a little help, but I'll just give you some guidence rather than solve it for you ;) Plus I'm not 100% on my psuedo code so I'll just write it mainly in C# which you can interpret into pseudo code.

Create an application in which you create an array of 20 Employee objects. In turn, pass each Employee object to a method that accepts an Employee, prompts the user for necessary data, and returns a "filled" Employee object to the array.

Well in C# first you would create the Employee object, which looks like this

class Employee
{
public int Id;
public string Name;
public string Surname;
public string Address;
public string City;
public string State;
public string JobTitle;
public float HourlyPayRate;
public int JobDescription;
public int InsurancePlan;

public Employee()
{
}

public Employee(int id, string name, string surname, string address, string city, string state, string jobTitle, float hourlyPayRate, int jobDescription, int insurancePlan)
{
Id = id;
Name = name;
...
}
}

An array of these looks like this

public Employee[] EmployeeArray = new Employee[20];

Now we have 20 of them and we can reference them EmployeeArray[0] to EmployeeArray[19].

Now we need to create a loop to loop through these 20 employee object pointers and fill them with data in another method.

for(int i=0; i<20; i++)
GetEmployeeData(EmployeeArray[i]);

public void GetEmployeeData(Employee emp)
{
Console.WriteLine("Enter Employee Name");
emp.Name = Console.ReadLine();
...
}

Pass the Employee array to a method that counts the number of Employees in each of the 10 job description categories and displays a count of each.

Okay we have Job Description Categories, so for this we will just create an array of ints for them

public int[] JobDescCategories =
{
1,
2,
...
3
}

public void CountEachJobDesc()
{
int[] jobDescCount = new int[10];

for(int i=0; i<EmployeeArray.Length; i++)
{
for(int j=0; j<10; j++)
{
if(EmployeeArray[i].JobDescription == JobDescCategories[j])
jobDescCount[j]++;
}
}

for(int i=0; i<10; i++)
Console.WriteLine(JobDescCategories[i] + " : " + jobDescCount[i].ToString());

Pass the Employee array to a method that counts the number in each of the two insurance plans and displays a count of each.

Okay just follow my previous example but do it for InsurancePlan.

Pass the Employee array to a method that sorts the Employees in ascending ID number order and display a list of the first and last names of the Employees in ID number order.

Well in C# you would implement IComarable and write your own overridden CompareTo() method. But obviously they want you to do some leg work here.

Bubble sort should be fine for this.

public void BubbleSortEmployees(Employee[] EmployeeArray)
{
Employee tempEmployee;

for(int i = EmployeeArray.Length - 1; i >= 0; i--)
{
for(int j = 1; j <= i; j++)
{
if(EmployeeArray[j-1].Id > EmployeeArray[j].Id)
{
tempEmployee = EmployeeArray[j-1];
EmployeeArray[j-1] = EmployeeArray[j];
EmployeeArray[j] = tempEmployee;
}
}
}
}

BubbleSortEmployees(EmployeeArray);
for(int i=0; i<EmployeeArray.Length; i++)
Console.WriteLine(EmployeeArray[i].Id + ":" + EmployeeArray[i].Name + ":" + EmployeeArray[i].Surname);

Create an application that continues to prompt the user for Employee data and writes the data to a file; the application continues until the user enters a 0 for an ID number to indicate the desire to quit. While the ID number is not zero, prompt the user for a value for each Employee field and assign it to an Employee object, except DO NOT prompt for city, state, job title, or hourly pay rate.

Any time the user enters an invalid field value, continue to reprompt the user for the same data. Only when a data item is valid, assign it to the appropriate field. Invalid field values are:

An employee ID number that is greater than 999

A ZIP code that is not in a list of allowed ZIP codes

A job description that is not between 10 and 19 inclusive

An insurance plan code that is not 1 or 2

int[] ValidZipCodes =
{
123,
456,
789
}

while(true)
{
Employee myEmployee = new Employee();
int Id = 0;

do
{
Console.WriteLine("Enter Id");
Id = Int.Parse(Console.ReadLine());

if(Id == 0)
break;
}
while(Id <= 999)

if(Id == 0)
break;

myEmployee.Id = Id;

bool validZip = false;
int zipCode = 0;

do
{
Console.WriteLine("Enter ZipCode");
zipCode = Int.Parse(Console.ReadLine());

for(int i=0; i<ValidZipCodes.Length; i++)
if(zipCode == ValidZipCodes[i])
validZip = true;
}
while(!validZip)

myEmployee.ZipCode = zipCode;

int jobDescription = 0;

do
{
Console.WriteLine("Enter Job Description");
jobDescription = Int.Parse(Console.ReadLine());
}
while(!(jobDescription >= 10 && jobDescription <= 19))

myEmployee.JobDescription = jobDescription;

int insurancePlan = 0;

do
{
Console.WriteLine("Enter Insurance Plan");
insurancePlan = Int.Parse(Console.ReadLine());
}
while(insurancePlan != 1 && insurancePlan != 2)

myEmployee.InsurancePlan = insurancePlan;

// Write myEmployee data to a file
}

Now do I get a cookie? :lol:

Posted

well i would love to help

but

i only dabbled in c++ self taught

ive made a small game and an annoying virus (good virus lol)

well im going to step out of this chat before i make myself sound like more of a noob lol :blink:

Posted

@Kaze:

Thanks for the help! :)

To my dismay, I was a little more off than I thought. My array skills look like they need touching up somewhat. The Bubble Sorting was something I figured needed to be employed, I just needed to hear it from someone else. After all, we learned methods to use instead of bubble sorting, so why not use the supposedly defunct method for the assignment? hehheh! I really appreciate your guidence, wise one!

As for your cookie...

<?php 

$user = $_POST['user'];
$color = $_POST['color'];
$self = $_SERVER['PHP_SELF'];

if( ( $user != null ) and ( $color != null ) )
{
setcookie( "firstname", $user , time() + 86400 ); // 24 hours
setcookie( "fontcolor", $color, time() + 86400 );
header( "Location:cookie2.php" );
exit();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Stuff by tedd</title>
</head>

<body>

<h1>tedd's cookie stuff</h1>

<hr>

<form action ="<?php echo( $self ); ?>" method = "post">

Please enter your first name:
<input type = "text" name = "user"><br><br>

Please choose your favorite font color:<br>
<input type = "radio" name = "color" value = "Red">Red
<input type = "radio" name = "color" value = "Green">Green
<input type = "radio" name = "color" value = "Blue">Blue
<br><br>
<input type = "submit" value = "submit">
</form>

<br/>
<hr>

</body>
</html>
</html>

Thanks again! I owe ya one! :)

Guest
This topic is now closed to further replies.
×
×
  • Create New...