bcg_81
asked on
Arrays
I have an assignment and need some guidance please. I am new to programming so please take that into account. Thank you.
Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas.
Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas.
At what language this should be written? What exactly you now about programing?
Independent of your programming skills, I always write programs / routines in pseudo code first. Pseudo code is independent of the language you are using to write the application in. This is your design.
So I'd start with 3 pieces of pseudo code or design. One is for getting the input / collecting your family members. Two is determining and printing the average age. Three is determining and printing who is living in Texas.
So I'd start with 3 pieces of pseudo code or design. One is for getting the input / collecting your family members. Two is determining and printing the average age. Three is determining and printing who is living in Texas.
ASKER
Well, Its confusing because we code in C++ but we use Raptor. I know that not all C++ code is useful in Raptor.
So I would start
Declare Names[100] string // I would need to set all three within a loop and set index= index +1??
Declare Location[100] string
Declare Age[100] as integer
Call Compute_Average
So I would start
Declare Names[100] string // I would need to set all three within a loop and set index= index +1??
Declare Location[100] string
Declare Age[100] as integer
Call Compute_Average
I do not know Raptor.
All this could be done with class or in structure. The result could be written to a file. And than you can read the information from the file and do the needed changes.
http://en.wikipedia.org/wiki/C%2B%2B_classes
http://linux.die.net/man/3/fopen
http://www.learn-programming.za.net/programming_c_learn10.html
http://www.cplusplus.com/reference/clibrary/cmath/
All this could be done with class or in structure. The result could be written to a file. And than you can read the information from the file and do the needed changes.
http://en.wikipedia.org/wiki/C%2B%2B_classes
http://linux.die.net/man/3/fopen
http://www.learn-programming.za.net/programming_c_learn10.html
http://www.cplusplus.com/reference/clibrary/cmath/
ASKER
I just need to write the pseudocode. Once I write out the code, would you be willing to look over it and give me pointers? Thank you very much!
http://en.wikipedia.org/wiki/Struct_%28C_programming_language%29
struct member{
string name[100];
string Location[100];
int Age[];
};
struct
family{
int members; //num of members;
member * array;
};
You should firs receive the numbers of family and write it to numbers;
then in the code
family familyarray;
array = new familyarray->array[members ];
Then in cicle from 0 to family.members -1 you will enter the information for the members of the family
failyarray->array[index].n ame
failyarray->array[index].L ocation
failyarray->array[index].a ge
This can be done with a text file or from the console. It's up to you to decide but I think that it will be better with a text file
struct member{
string name[100];
string Location[100];
int Age[];
};
struct
family{
int members; //num of members;
member * array;
};
You should firs receive the numbers of family and write it to numbers;
then in the code
family familyarray;
array = new familyarray->array[members
Then in cicle from 0 to family.members -1 you will enter the information for the members of the family
failyarray->array[index].n
failyarray->array[index].L
failyarray->array[index].a
This can be done with a text file or from the console. It's up to you to decide but I think that it will be better with a text file
ASKER
I just submit it in word. Why is there not a [100] for int age? I think becsuse you are a master programmer that you over estimate my knowledge level. I am sure that your code is correct but I need to understand what you have wriiten down so please be patient with me. I also knwo that you are not a miracle worker wither! :) Im used to seeing code look like this
Main Module
Declare Member[10] as String //Create Arrays
Declare Money[10] as Float
Declare totalSaving as Float
Declare mostSavings as integer
For(i=0; i<10; i ++)
{
Write “Enter Name “
Input Member // This is where Names are input
Write “Enter Savings"
Input Money //This is where Savings is input.
}
Call Module Total_Savings // Subprogram is called to calculate total savings.
Call Module Most_Savings // Subprogram is called to calcualte Most Savings.
Write " Total Savings" + x // Output will display total Savings.
Write " Total Savings" + total
Write "Name of Person" +[index] //Displays person with the most savings.
Main Module
Declare Member[10] as String //Create Arrays
Declare Money[10] as Float
Declare totalSaving as Float
Declare mostSavings as integer
For(i=0; i<10; i ++)
{
Write “Enter Name “
Input Member // This is where Names are input
Write “Enter Savings"
Input Money //This is where Savings is input.
}
Call Module Total_Savings // Subprogram is called to calculate total savings.
Call Module Most_Savings // Subprogram is called to calcualte Most Savings.
Write " Total Savings" + x // Output will display total Savings.
Write " Total Savings" + total
Write "Name of Person" +[index] //Displays person with the most savings.
ASKER
struct // Struct is a variable?
family{
int members; //num of members;
member * array; //Why member * array?
};
You should firs receive the numbers of family and write it to numbers;
then in the code
Are you saying that a function should be done that is not included in the actual main module?
family{
int members; //num of members;
member * array; //Why member * array?
};
You should firs receive the numbers of family and write it to numbers;
then in the code
Are you saying that a function should be done that is not included in the actual main module?
My mistake
int age;
Every member of the family has just one age I suppose, the current age;
The sturcture family describes the hole family. The member "members" describes the number of members of the family. Each memeber of the family is described in the structure member with his name, age and location. In structrure family there is a dynamic array of the memebers of the family because I don't know how much are they. In family there is a dynamic array of the members of the family each described with name, age and location.
int age;
Every member of the family has just one age I suppose, the current age;
The sturcture family describes the hole family. The member "members" describes the number of members of the family. Each memeber of the family is described in the structure member with his name, age and location. In structrure family there is a dynamic array of the memebers of the family because I don't know how much are they. In family there is a dynamic array of the members of the family each described with name, age and location.
member * array - In family there is a dynamic array of the members of the family each described with name, age and location.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are correct, I have not covered what user_n discussed but I appreciate his comments. The code i showed you was from my last project, which I was lost. Ok, Thanks!!!! I will right it up withing the next couple of days and let you take a look at it if you dont mind. Thank you very much Tommy! and anyone else who responded. Please come back later! Thanks again ~ Brian
ASKER
Declare Names[100], Location[100] as string
Declare Age[100] as int
Declare AvgAge as float
Main Module
For (i = 0, i < 100, i ++)
{
Write "Please input family data!"
Write "Name"
Input Name
Write "Age"
Input Age
Write "Location"
Iput Location
}
Call Avg_Age sub program
Call Texas_ sub program
Output "AvgAge"
Output "Texas"
End
Sub program Avg_Age
For ???
Ok, I confused on how to set up a loop to calcualte the avg. I know that by adding them up and dividing by the number that ill get the avg but how would thi sbe written in pseudocode?
While ( i=0, i <100, i ++)
while ??
Declare Age[100] as int
Declare AvgAge as float
Main Module
For (i = 0, i < 100, i ++)
{
Write "Please input family data!"
Write "Name"
Input Name
Write "Age"
Input Age
Write "Location"
Iput Location
}
Call Avg_Age sub program
Call Texas_ sub program
Output "AvgAge"
Output "Texas"
End
Sub program Avg_Age
For ???
Ok, I confused on how to set up a loop to calcualte the avg. I know that by adding them up and dividing by the number that ill get the avg but how would thi sbe written in pseudocode?
While ( i=0, i <100, i ++)
while ??
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So,
Call Sub program Avg_Age
Declare Sum as int
Delclare avg as float
For (i=0, i< 100, i ++)
sum = sum + Age
AvgAge = sum/10
End Sub Program
Can you tell me how things look overall so far? Any pointers? Anything that looks wrong?
Call Sub program Avg_Age
Declare Sum as int
Delclare avg as float
For (i=0, i< 100, i ++)
sum = sum + Age
AvgAge = sum/10
End Sub Program
Can you tell me how things look overall so far? Any pointers? Anything that looks wrong?
ASKER
I would need to set Avg to 0 correct?
Declare Sum as int
Delclare avg as float
set AvgAge to = 0
For (i=0, i< 100, i ++)
sum = sum + Age
AvgAge = sum/10
End Sub Program
Declare Sum as int
Delclare avg as float
set AvgAge to = 0
For (i=0, i< 100, i ++)
sum = sum + Age
AvgAge = sum/10
End Sub Program
ASKER
For finding the Person who lives in Texas......
Im a little puzzled here.
I know we need to look at Location
Could we say...
Call Texas_ sub program
Declare j as string
Set j = Texas
For (i=o, i !=j, i ++)
So I set j = Texas and I need to get the name of the family member who lives in Texas. I must compare name[100] to Location[100]. Im confused here.
Im stuck here. I also have to consider if no one lives in Texas correct?
Im a little puzzled here.
I know we need to look at Location
Could we say...
Call Texas_ sub program
Declare j as string
Set j = Texas
For (i=o, i !=j, i ++)
So I set j = Texas and I need to get the name of the family member who lives in Texas. I must compare name[100] to Location[100]. Im confused here.
Im stuck here. I also have to consider if no one lives in Texas correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tell me what you think about this please. Also, Im questoning my output " Texas" int he main module. In order for that to output Texas, it must be declared correct. I think that might be wrong!
Declare Names[100], Location[100] as string
Declare Age[100] as int
Declare AvgAge as float
Main Module
For (i = 0, i < 100, i ++)
{
Write "Please input family data!"
Write "Name"
Input Name
Write "Age"
Input Age
Write "Location"
Iput Location
}
Call Avg_Age sub program
Call Texas_ sub program
Output "AvgAge"
Output "Texas"
End
Avg_age Sub program
Declare Sum as int
Delclare avg as float
set sum to = 0
For (i=0, i< 100, i ++)
sum = sum + Age[i ]
AvgAge = sum/10
End Sub Program
Subprogram Texas_
For (i=0, i< 100, i ++)
If Location == Texas
Then output Name[i ]
End if
End sub program
Declare Names[100], Location[100] as string
Declare Age[100] as int
Declare AvgAge as float
Main Module
For (i = 0, i < 100, i ++)
{
Write "Please input family data!"
Write "Name"
Input Name
Write "Age"
Input Age
Write "Location"
Iput Location
}
Call Avg_Age sub program
Call Texas_ sub program
Output "AvgAge"
Output "Texas"
End
Avg_age Sub program
Declare Sum as int
Delclare avg as float
set sum to = 0
For (i=0, i< 100, i ++)
sum = sum + Age[i ]
AvgAge = sum/10
End Sub Program
Subprogram Texas_
For (i=0, i< 100, i ++)
If Location == Texas
Then output Name[i ]
End if
End sub program
In real code, you would need to put quotes around "Texas" for the if.
Also, for the average, shouldn't you use /100 not /10 ?
For the input function, you might want to specify that the data is going in the arrays. Like
Write "Name"
Input Name[i ]
Also, for the average, shouldn't you use /100 not /10 ?
For the input function, you might want to specify that the data is going in the arrays. Like
Write "Name"
Input Name[i ]
Other then that it looks good.
ASKER
Yes, /100.....In the main module where is says Output "Texas" this is wrong correct? Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I appreciate all comments but I found the most help for my question from tommy. Thank you very much.