I have already abandoned this site because WordPress acts like a bank and always asks you about going premium.
![](https://i0.wp.com/fc05.deviantart.net/fs18/f/2007/145/6/3/Abandon_Hope_by_Voorhees87.jpg)
Goodbye!
I have already abandoned this site because WordPress acts like a bank and always asks you about going premium.
Goodbye!
via Paddylast Inc.
this is HOT!!!!
via Paddylast Inc.
/*
**Name: Mark Anthony A. Cabanlit
**Student Number: 2010-35479
**Date Began: October 2, 2010
**Date Finished: October 12, 2010
**File description: The student Record Management System (SRMS) is an array-based
application used to register, view, modify and/or delete
student records.
*/
#include "Prototype.h"
int main(void)
{
introSRMS();
for(;;)//allows the program to continue and it only stops if the user wants it to.
{
overall();
}
return 0;
}
int modifyGet(void)
{
int modifyNumber;
int limit;
int u = -1;
int i;
limit = vacantSlots();//get the number of students inside the struct
if(limit == 0)//checks if there are already datas inside the struct
{
printf("\nNo data ENTRIES available!");
printf("\nRedirecting to main.");
overall();
}
else
{
printf("\n\tEnter student number:");
scanf("%i", &modifyNumber);
for(i = 0; i < limit; i++)
{
if (modifyNumber == stud[i].stud_number)//searches the location of the given student number
{
u = i;
break;
}
else
{
u = -1;
}
}
return u;
}
}
void modifyMain(void)
{
int x;
int modifyChoice;
int limit;
limit = vacantSlots();
x = modifyGet();
if (x == -1)//checks if the student number exists
{
printf("\n\t\tStudent does not exist!");
printf("\n\t\tRedirecting to main.");
overall();
}
else if (limit > 0)//falsified when there is no entry inside the structure
{
printf("\n\tWhat would you like to modify from %s?", stud[x].first_name);
space();
printf("\n\t\t1. Modify All");
printf("\n\t\t2. Modify Last Name");
printf("\n\t\t3. Modify First Name");
printf("\n\t\t4. Modify Birthdate");
printf("\n\t\t5. Modify Course");
printf("\n\t\t6. Go back to main.");
space();
printf("\n\t\tEnter choice:");
scanf("%i", &modifyChoice);
fflush(stdin);
switch (modifyChoice)
{
case 1: space();
printf("\n-----------------------------------Modify All-----------------------------------");
space();
modifyAll(x);
break;
case 2: space();
printf("\n--------------------------------Modify Last Name--------------------------------");
space();
modifyLast(x);
break;
case 3: space();
printf("\n--------------------------------Modify First Name-------------------------------");
space();
modifyFirst(x);
break;
case 4: space();
printf("\n--------------------------------Modify Birth Date-------------------------------");
space();
modifyBirthday(x);
break;
case 5: space();
printf("\n----------------------------------Modify Course---------------------------------");
space();
modifyCourse(x);
break;
case 6: space();
overall();
break;
default: printf("\nInvalid Choice:");
space();
printf("\nRedirected to main.");
overall();
}
}
}
void modifyLast(int i)
{
printf("\n\tEnter new last name:");
scanf("%s", &stud[i].last_name);
}
void modifyFirst(int i)
{
printf("\n\tEnter new first name:");
scanf("%s", &stud[i].first_name);
}
void modifyCourse(int i)
{
printf("\n\tEnter new course:");
scanf("%s", &stud[i].course);
}
void modifyBirthday(int i)
{
printf("\n\tEnter new birthday (yyyy-mm-dd):");
scanf("%s", &stud[i].birthday);
}
void modifyAll(int i)
{
int j;
int count = 0;
int number;
if (i > 0)//will only be true if there are data inside the struct
{
printf("\n\tEnter new student number:");
scanf("%i", &number);
for(j = 0; j < i; j++)
{
if (number == stud[j].stud_number)
{
printf("\nStudent number already taken!!");
count = count + i;
break;
}
else
{
count--;
}
}
if (count < 0)//continuation after the verification of student number
{
stud[i].stud_number = number;
printf("\n\tEnter new last name:");
scanf("%s", &stud[i].last_name);
printf("\n\tEnter new first name:");
scanf("%s", &stud[i].first_name);
printf("\n\tEnter new birthday (yyyy-mm-dd):");
scanf("%s", &stud[i].birthday);
printf("\n\tEnter new course:");
scanf("%s", &stud[i].course);
}
}
else
{
printf("\n\tEnter new student number:");
scanf("%i", &stud[i].stud_number);
printf("\n\tEnter new last name:");
scanf("%s", &stud[i].last_name);
printf("\n\tEnter new first name:");
scanf("%s", &stud[i].first_name);
printf("\n\tEnter new birthday (yyyy-mm-dd):");
scanf("%s", &stud[i].birthday);
printf("\n\tEnter new course:");
scanf("%s", &stud[i].course);
}
}
void eraseMain(void)
{
int eraseChoice;
printf("\n\tWhat would you like to erase");
space();
printf("\n\t\t1. Delete all");
printf("\n\t\t2. Delete one");
printf("\n\t\t3. Go back to main");
space();
printf("\n\tEnter your choice:");
scanf("%i", &eraseChoice);
fflush(stdin);
switch (eraseChoice)
{
case 1: printf("\n-------------------------------Delete all Students------------------------------");
space();
eraseAll();
break;
case 2: printf("\n---------------------------------Delete a Student-------------------------------");
space();
eraseOne();
break;
case 3: overall();
default: printf("\nInvalid Choice");
}
}
void eraseOne(void)
{
int u = -1;//signals if the student does not exist
int i;
int v;
int limit;
int search;
printf("\n\tEnter the student number:");
scanf("%i", &search);
limit = vacantSlots();
for(i = 0; i < limit; i++)
{
if (search == stud[i].stud_number)//checks if the imputed student number is available
{
u = i;
break;
}
}
if (u < 0)
{
printf("\nStudent does NOT exist!!");
}
else if (u == i)//makes sure that u is equal to i
{
printf("\nEntries about %s has been deleted.", stud[u].first_name);
stud[u].stud_number = '\0';
stud[u].last_name[0] = '\0';
stud[u].first_name[0] = '\0';
stud[u].birthday[0] = '\0';
stud[u].course[0] = '\0';
for(u = i; u < limit; u++)//enables the datas next to the deleted data to fill up the missing areas
{
stud[u].stud_number = stud[u+1].stud_number;
//loops the string in order for it to replace the missing ones
for(v = 0; v < strlen(stud[u].last_name)+1; v++)
{
stud[u].last_name[v] = stud[u+1].last_name[v];
}
for(v = 0; v < strlen(stud[u].first_name)+1; v++)
{
stud[u].first_name[v] = stud[u+1].first_name[v];
}
for(v = 0; v < strlen(stud[u].birthday)+1; v++)
{
stud[u].birthday[v] = stud[u+1].birthday[v];
}
for(v = 0; v < strlen(stud[u].course)+1; v++)
{
stud[u].course[v] = stud[u+1].course[v];
}
}
}
}
void eraseAll(void)
{
char eraseLetter;
int limit;
int j;
limit = vacantSlots();//gets the number of students inside the struct
printf("Are you sure you want to delete all the information?");
printf("\nEnter y for YES and n for NO:");
fflush(stdin);
eraseLetter = getchar();
if (eraseLetter == 'y')
{
for(j = 0; j < limit; j++)
{
//makes all the values to null
stud[j].stud_number = '\0';
stud[j].last_name[0] = '\0';
stud[j].first_name[0] = '\0';
stud[j].birthday[0] = '\0';
stud[j].course[0] = '\0';
}
printf("\nAll entries have been deleted!");
}
if (eraseLetter == 'n')
{
space();
printf("\nRedirecting to main.");
overall();
}
if ((eraseLetter != 'y') && (eraseLetter != 'n'))
{
space();
printf("\nInvalid choice");
printf("\nRedirecting to main.");
overall();
}
}
void inputValues(void)
{
int i;
int j;
int flag = 0;
i = vacantSlots();
space();
printf("\nEnter student information.");
space();
printf("\n\tEnter Student Number:");
scanf("%i", &stud[i].stud_number);
if (i != 0)//does not work if the struct is empty
{
for(j = 0; j < i; j++)
{
if (stud[i].stud_number == stud[j].stud_number)
{
//turns all the inputed values to null to make sure it does not
//mess with the program
stud[i].stud_number = '\0';
stud[i].last_name[0] = '\0';
stud[i].first_name[0] = '\0';
stud[i].birthday[0] = '\0';
stud[i].course[0] = '\0';
printf("\nStudent number already taken!!");
flag = flag + i;//signal that the student number is already taken
break;
}
else
{
flag--;//signals that the student number is not taken
}
}
}
else//satisfies the condition that if i is 0
{
printf("\n\tEnter last name:");
scanf("\n%s", stud[i].last_name);
printf("\n\tEnter first name:");
scanf("%s", stud[i].first_name);
printf("\n\tEnter birthday (yyyy-mm-dd):");
scanf("%s", stud[i].birthday);
printf("\n\tEnter course:");
scanf(" %s", stud[i].course);
}
if (flag < 0)//continuation for flag--
{
printf("\n\tEnter last name:");
scanf("%s", stud[i].last_name);
printf("\n\tEnter first name:");
scanf("%s", stud[i].first_name);
printf("\n\tEnter birthday (yyyy-mm-dd):");
scanf("%s", stud[i].birthday);
printf("\n\tEnter course:");
scanf("%s", stud[i].course);
}
}
int vacantSlots(void)
{
int v;
//loops until stud[v].stud_number has a null value.
//loops until v is equal to MAX
for(v = 0; stud[v].stud_number && v < MAX; ++v)
{
continue;
}
if(v == MAX)
{
return -1;
}
return v;
}
void displayMain(void)
{
int displayChoice;
printf("\n\tWhat would you like to display?");
space();
printf("\n\t\t1. Display all");
printf("\n\t\t2. Display one");
printf("\n\t\t3. Go back to main");
space();
printf("\n\tEnter your choice:");
scanf("%i", &displayChoice);
fflush(stdin);
switch (displayChoice)
{
case 1: printf("\n-------------------------------Display all Students-----------------------------");
space();
displayAll();
break;
case 2: printf("\n---------------------------------Display a Student------------------------------");
space();
displayOne();
break;
case 3: overall();
default: printf("\nInvalid Choice");
}
}
void displayAll(void)
{
int u;
int x = 0;
int limit;
bubbleSort(stud);
space();
space();
printf("\n Student No. | Last Name | First Name | Birthday | Course ");
space();
space();
limit = vacantSlots();//gets the number of students inside struct
for(u = 0; u < limit; u++)
{
printf(" %i", stud[u].stud_number);
printf("\t %s", stud[u].last_name);
printf("\t %s", stud[u].first_name);
printf("\t %s", stud[u].birthday);
printf("\t %s", stud[u].course);
space();
space();
//if you want the arrays to be aligned left, use the code below
/*printf("%12i", stud[u].stud_number);
printf("%15s", stud[u].last_name);
printf("%17s", stud[u].first_name);
printf("%15s", stud[u].birthday);
printf("%15s", stud[u].course);*/
}
}
void displayOne(void)
{
int u = -1;
int i;
int limit;
int search;
printf("\n\tEnter the student number:");
scanf("%i", &search);
limit = vacantSlots();
for(i = 0; i < limit; i++)
{
if (search == stud[i].stud_number)//verifies if the student number exists
{
u = i;
break;
}
}
if (u < 0)
{
printf("\nStudent does NOT exist!!");
}
else
{
printf("\n Student No. | Last Name | First Name | Birthday | Course ");
space();
space();
printf(" %i", stud[u].stud_number);
printf("\t %s", stud[u].last_name);
printf("\t %s", stud[u].first_name);
printf("\t %s", stud[u].birthday);
printf("\t %s", stud[u].course);
space();
space();
//if you want the arrays to be aligned left, use the code below
/*printf("%12i", stud[u].stud_number);
printf("%15s", stud[u].last_name);
printf("%17s", stud[u].first_name);
printf("%15s", stud[u].birthday);
printf("%15s", stud[u].course);*/
}
}
void introSRMS(void)
{
space();
space();
printf("-------------------------STUDENT RECORD MANAGEMENT SYSTEM-----------------------");
space();
printf("\nThe student Record Management System (SRMS) is an array-based application used ");
printf("\nto register, view, modify and/or delete student records.");
space();
loadArray(stud);
}
int choiceMain(void)
{
int choice_Main;
int limit;
space();
space();
printf("--------------------------------------MAIN--------------------------------------");
space();
printf("\nWhat would you like to do?");
space();
printf("\n1. Add Student");
printf("\n2. Modify Student");
printf("\n3. Display");
printf("\n4. Delete");
printf("\n5. Exit");
space();
printf("\nPlease enter your choice now:");
scanf("%i", &choice_Main);
fflush(stdin);
return choice_Main;
}
void space(void)
{
printf("\n");
}
void overall(void)
{
int choice;
int limit;
limit = vacantSlots();
choice = choiceMain();
switch (choice)
{
case 1: space();
printf("\n-----------------------------------Add Student----------------------------------");
space();
inputValues();
break;
case 2: space();
printf("\n----------------------------------Modify Student--------------------------------");
space();
modifyMain();
break;
case 3: space();
printf("\n---------------------------------Display Records--------------------------------");
space();
displayMain();
break;
case 4: space();
printf("\n---------------------------------Delete Records---------------------------------");
space();
eraseMain();
break;
case 5: bubbleSort(stud);
displayArray(stud);
exit(0);
break;
default: printf("\nInvalid Input.");
}
}
void displayArray(struct STUDENT stud[])
{
FILE*fp;
int i;
int j;
i = vacantSlots();
STUDENT temp;
fp = fopen("Records.txt","w");//opens records.txt
//fprintf(fp,"%-12s %-12s %-12s %-12s %s\n","Student No.","Family Name","First Name","Birthdate","Course");
for (j = 0; j < i; j++)
{
temp = stud[j];
fprintf(fp,"%-12i %-12s %-12s %-12s %s\n",temp.stud_number,temp.last_name,temp.first_name,temp.birthday,temp.course);
}
fclose(fp);
}
void loadArray(struct STUDENT stud[])
{
FILE *fp;
int i;
i = vacantSlots();
STUDENT temp;
fp = fopen("Records.txt", "r");//loads records.txt
while (1)
{
fscanf(fp,"%i %s %s %s %s",&temp.stud_number, temp.last_name, temp.first_name, temp.birthday, temp.course);
if (feof(fp))
{
break;
}
stud[i] = temp;
i++;
if(i > MAX)
{
printf("\nData is too large!");
fclose(fp);
exit(1);
}
}
fclose(fp);
}
void bubbleSort(struct STUDENT stud[])
{
int i, j;
int limit;
limit = vacantSlots();
STUDENT temp;
for (i = (limit - 1); i >= 0; i--)//counter
{
for (j = 1; j <= i; j++)//
{
if (stud[j].stud_number < stud[j-1].stud_number)//compares two members of the struct
{
temp = stud[j-1];//gives temp the value of the next element on struct
stud[j-1] = stud[j];//gives the second value the first value
stud[j] = temp;//final value of stud
}
}
}
}
//Sources:
//http://www.java2s.com/Code/C/Structure/Asimplemailinglistexampleusinganarrayofstructures.htm
//for the vacantSlot function
//http://kalyan-city.blogspot.com/2009/07/bubble-sorting-c-program-bubble-sort.html
//for Bubble Sort
//Mr. Chito Patiño
//for all the lessons that he taught us specially on file handling
/*
201035479 Cabanlit Mharkie 1993-09-23 BSCS
201035432 Bayon-on James 1993-12-14 BSCS
201035458 Marikit Peter 1993-01-29 BSCS
201035469 Lianza Christian 1993-12-14 BAPS
201035471 Geronimo Sarah 1995-65-23 BSMath
201045632 Fortalejo Jewel 1995-65-13 BSGE
*/
from the file prototype.h
/* **Name: Mark Anthony A. Cabanlit **Student Number: 2010-35479 **Date Began: October 2, 2010 **Date Finished: October 12, 2010 **File description: This .h file contains all the function declarations of Machine_Problem.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 100 struct STUDENT { int stud_number; char last_name[30]; char first_name[30]; char birthday[30]; char course[30]; }stud[MAX]; void overall(); /* **Function Name: **Function Description: **Description of Parameters: **Description of Return Value: **Date Began: **Date Finished: */ void introSRMS(); /* **Function Name: introSRMS **Function Description: Prints the name and description of the program. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 2, 2010 **Date Finished: October 2, 2010 */ int choiceMain(); /* **Function Name: choiceMain **Function Description: Enables user to input his choice on what to do with the program. (e.g. Add, Modify, etc.) **Description of Parameters: No parameters. **Description of Return Value: int, value of selected operation. **Date Began: October 2, 2010 **Date Finished: October 2, 2010 */ int vacantSlots(); /* **Function Name: vacantSlots **Function Description: Checks the latest vacant value of the array of structures. Somewhat the same with static int. **Description of Parameters: No parameters. **Description of Return Value: int, the number of students inside the structure. **Date Began: October 2, 2010 **Date Finished: October 3, 2010 */ void inputValues(); /* **Function Name: inputValues **Function Description: Allows user to input the information of a student. Prompts user if the student number already exists. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 2, 2010 **Date Finished: October 4, 2010 */ void modifyMain(); /* **Function Name: modifyMain **Function Description: Allows user to choose on what to modify. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 7, 2010 **Date Finished: October 7, 2010 */ int modifyGet(); /* **Function Name: modifyGet **Function Description: Verifies the student number to be modified by the user. **Description of Parameters: No parameters. **Description of Return Value: int, location of the student number if it holds true but returns -1 if false. **Date Began: October 7, 2010 **Date Finished: October 7, 2010 */ void modifyAll(int); /* **Function Name: modifyAll **Function Description: Modifies the student number, name, course and birthday of a student given its student number as input. **Description of Parameters: int, the address of the student to be modified. **Description of Return Value: No return value. **Date Began: October 7, 2010 **Date Finished: October 8, 2010 */ void modifyLast(int); /* **Function Name: modifyLast **Function Description: Modifies last name of a student given its student number as input. **Description of Parameters: No parameters. **Description of Return Value: int, the address of the student to be modified. **Date Began: October 7, 2010 **Date Finished: October 7, 2010 */ void modifyFirst(int); /* **Function Name: modifyFirst **Function Description: Modifies first name of a student given its student number as input. **Description of Parameters: No parameters. **Description of Return Value: int, the address of the student to be modified. **Date Began: October 7, 2010 **Date Finished: October 7, 2010 */ void modifyCourse(int); /* **Function Name: modifyCourse **Function Description: Modifies course of a student given its student number as input. **Description of Parameters: No parameters. **Description of Return Value: int, the address of the student to be modified. **Date Began: October 7, 2010 **Date Finished: October 7, 2010 */ void modifyBirthday(int); /* **Function Name: modifyBirthday **Function Description: Modifies birthday of a student given its student number as input. **Description of Parameters: No parameters. **Description of Return Value: int, the address of the student to be modified. **Date Began: October 7, 2010 **Date Finished: October 7, 2010 */ void displayAll(); /* **Function Name: displayAll **Function Description: Dislays all the student number, first name, family name, birthdate, and course. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 3, 2010 **Date Finished: October 4, 2010 */ void displayOne(); /* **Function Name: displayOne **Function Description: Dislays the student number, first name, family name, birthdate, and course of a certain student given his student number. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 3, 2010 **Date Finished: October 4, 2010 */ void displayMain(); /* **Function Name: displayMain **Function Description: Allows user to select what to display. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 4, 2010 **Date Finished: October 4, 2010 */ void eraseAll(); /* **Function Name: eraseAll **Function Description: Allows user to delete all datas inside the program but before deleting, it asks the user to confirm the said task. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 4, 2010 **Date Finished: October 5, 2010 */ void eraseOne(); /* **Function Name: eraseOne **Function Description: Allows user to delete the information of one student given his student number and the function also prompts the user if the student does not exist. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 5, 2010 **Date Finished: October 6, 2010 */ void eraseMain(); /* **Function Name:eraseMain **Function Description: Allows user to select what to erase. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 6, 2010 **Date Finished: October 6, 2010 */ void bubbleSort(struct STUDENT stud[], int); /* **Function Name: bubbleSort **Function Description: Arranges the student numbers in increasing order together with their other attributes. **Description of Parameters: struct, the main structure that contains all the collected data. int, size or the number of entries inside the struct. **Description of Return Value: No return value. **Date Began: October 2, 2010 **Date Finished: October 12, 2010 */ void loadArray(struct STUDENT stud[]); /* **Function Name: loadArray **Function Description: Loads the array from records.txt to the program. **Description of Parameters: struct, the main struct used in the program. **Description of Return Value: No return value. **Date Began: October 9, 2010 **Date Finished: October 9, 2010 */ void displayArray(struct STUDENT stud[]); /* **Function Name: displayArray **Function Description: displays the information gathered from the the program to records.txt **Description of Parameters: struct, the main struct used in the program. **Description of Return Value: No return value. **Date Began: October 9, 2010 **Date Finished: October 9, 2010 */ void space(); /* **Function Name: space **Function Description: Prints "\n" or enter. **Description of Parameters: No parameters. **Description of Return Value: No return value. **Date Began: October 2, 2010 **Date Finished: October 2, 2010 */
/*Program Description: A program that can list 10-15 employees with the following
attributes: (1)Name (2)Id Number and (3) Salary.
The program will also show the average salary in the
company and it will show the employees with highest
salary.
*Author: Mark Anthony Cabanlit
*Date Began: September 28, 2010 *Date Finished: October 1, 2010
*Filename: exer5_1.C
*/
#include <stdio.h>
struct EMPLOYEE {
char name[30];
int number;
float salary;
};
void inputValues(struct EMPLOYEE emp[],float size);
void outputValues(struct EMPLOYEE[],float size);
float average(struct EMPLOYEE emp[], float size);
float highest(struct EMPLOYEE emp[], float size);
void printAverage(struct EMPLOYEE emp[], float size);
void printHighest(struct EMPLOYEE emp[], float size);
float enterSize();
void space();
int main(void)
{
struct EMPLOYEE emp[20];
float size;
size = enterSize();
inputValues(emp, size);
outputValues(emp, size);
printAverage(emp, size);
printHighest(emp, size);
return 0;
}
float enterSize(void)
{
float x;
float n;
printf("\nPlease enter the number of employees:");
scanf("%f", &x);
if ((x > 15)||(x < 10))
{
printf("\nInvalid number of EMPLOYEES!!");
n = 0;
}
else
{
n = x;
}
return n;
}
void inputValues(struct EMPLOYEE emp[],float size)
{
int i;
for(i = 0; i < size; ++i)
{
space();
printf("\nEmployee %i", i+1);
space();
printf("\n\tEnter name of employee:");
scanf("%s", &emp[i].name);
printf("\n\tEnter Id Number:");
scanf("%i", &emp[i].number);
printf("\n\tEnter salary:");
scanf("%f", &emp[i].salary);
}
}
void outputValues(struct EMPLOYEE emp[],float size)
{
int i;
space();
space();
for(i = 0; i < size; ++i)
{
printf("\nEmployee %i", i+1);
space();
printf("\n\tName:\t\t%s", emp[i].name);
printf("\n\tId Number:\t%i", emp[i].number);
printf("\n\tSalary:\t\t%.2f", emp[i].salary);
space();
space();
}
}
float average(struct EMPLOYEE emp[], float size)
{
int i;
float total = 0;
float ave;
for(i = 0; i < size; ++i)
{
total = total + emp[i].salary;
}
ave = total/size;
return ave;
}
float highest(struct EMPLOYEE emp[], float size)
{
int i;
float highest = emp[0].salary;
for(i = 1; i < size; ++i)
{
if(highest < emp[i].salary)
{
highest = emp[i].salary;
}
}
return highest;
}
void printAverage(struct EMPLOYEE emp[], float size)
{
float ave;
ave = average(emp, size);
if (size == 0)
{
printf("");
}
else
{
space();
printf("\nAverage Salary: %.2f", ave);
space();
}
}
void printHighest(struct EMPLOYEE emp[], float size)
{
float high;
int i;
high = highest(emp, size);
for(i = 0; i < size; i++)
{
space();
printf("\nEmployees with the highest salary:");
break;
}
for(i = 0; i < size; ++i)
{
if(high == emp[i].salary)
{
printf("\n\t%s", emp[i].name);
}
}
}
void space()
{
printf("\n");
}
#include <stdio.h>
void inputValues(int[], int);
void getUnion(int[], int[], int, int[], int);
void getIntersection(int[], int[], int, int[], int);
void getDifferenceA(int[], int[], int, int[], int);
void getDifferenceB(int[], int[], int, int[], int);
void printValues(int[], int);
void space();
int main(void)
{
int numbers1[5];
int numbers2[5];
int unionSet[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int intersectionSet[5] = {-1, -1, -1, -1, -1};
int differenceSetA[5] = {-1, -1, -1, -1, -1};
int differenceSetB[5] = {-1, -1, -1, -1, -1};
inputValues(numbers1, 5);
inputValues(numbers2, 5);
printf("\nFirst Array\n");
space();
printValues(numbers1, 5);
printf("\nSecond Array\n");
space();
printValues(numbers2, 5);
getUnion(numbers1, numbers2, 5, unionSet, 10);
printf("\nUnion\n");
space();
printValues(unionSet, 10);
getIntersection(numbers1, numbers2, 5, intersectionSet, 5);
printf("\nIntersection\n");
space();
printValues(intersectionSet, 5);
getDifferenceA(numbers1, numbers2, 5, differenceSetA, 5);
printf("\nDifference A\n");
space();
printValues(differenceSetA, 5);
getDifferenceB(numbers1, numbers2, 5, differenceSetB, 5);
printf("\nDifference B\n");
space();
printValues(differenceSetB, 5);
return 0;
}
void space()
{
printf("\n");
}
void inputValues(int Array[], int size)
{
int i;
printf("\nEnter values for Array:\n");
for(i=0; i<size; i++)
{
printf("\tEnter a number: ");
scanf("%i", &Array[i]);
}
}
void getUnion(int Array1[], int Array2[], int sizeArray, int ArrayUnion[], int sizeUnion)
{
//tanang numbers nga naa sa duha ka arrays
int i, j;
int temp;
int l =0;
for(i=0;i<sizeArray;i++)
{
for(j=0;j<sizeArray;j++)
{
if(Array1[i]==Array2[j])
{
temp=1;
}
if(i==0)
{
ArrayUnion[l]=Array2[j];
l++;
}
}
if(temp!=1)
{
ArrayUnion[l]=Array1[i];
l++;
}
else
{
temp=0;
}
}
}
void getIntersection(int Array1[], int Array2[], int sizeArray, int ArrayIntersection[], int sizeIntersection)
{
//unsa ang numbers nga naa sila both.
int i, j;
int k = 0;
for(i=0;i<sizeArray;i++)
{
for(j=0;j<sizeArray;j++)
{
if(Array1[i]==Array2[j])
{
ArrayIntersection[k]=Array1[i];
k++;
}
}
}
}
void getDifferenceA(int Array1[], int Array2[], int sizeArray, int ArrayDifferenceA[], int sizeDifferenceA)
{
//unsa ang numbers nga naa sa Array1 but wala sa Array2
int i, j;
int total;
for(i=0;i<sizeArray;i++)
{
total = 0;
for(j=0;j<sizeArray;j++)
{
if(Array1[i]!=Array2[j])
{
total++;
}
if (total == 5)
{
ArrayDifferenceA[i] = Array1[i];
}
}
}
}
void getDifferenceB(int Array1[], int Array2[], int sizeArray, int ArrayDifferenceB[], int sizeDifferenceB)
{
//unsa ang numbers nga naa sa Array2 but wala sa Array1
int i, j;
int total;
for(i=0;i<sizeArray;i++)
{
total = 0;
for(j=0;j<sizeArray;j++)
{
if(Array2[i]!=Array1[j])
{
total ++;
}
if (total == 5)
{
ArrayDifferenceB[i] = Array2[i];
}
}
}
}
void printValues(int Array[], int size)
{
int i;
for(i=0; i<size; i++)
{
printf("\t%i", Array[i]);
}
}
#include <stdio.h>
int main(void){
int hold;
int *hold_ptr;
hold = 145;
hold_ptr = &hold;
printf(“\nThe variable hold = %i”, hold);
printf(“\nThe dereference pointer,*hold_ptr = %i”, *hold_ptr);
printf(“\nThe address, &hold, = %u”, &hold);
printf(“\nThe address,&hold_ptr = %u”, hold_ptr);
return 0;
}
Loops for Multiplication in Repeated Addition.
DO LOOP
#include <stdio.h>int main(void)
{ int x, y; int counter = 0; int result = 0;
printf(“\nEnter the two numbers that you wish to multiply.”); printf(“\n”); printf(“\nEnter first number:”); scanf(“%i”, &x); printf(“\nEnter second number:”); scanf(“%i”, &y);
do { result = result + x; counter = counter + 1; }while (counter <y);
printf(“\nThe result is %i”, result);
return 0;
}
FOR LOOP
#include <stdio.h>
int main(void)
{
int x, y;
int counter;
int result = 0;
printf(“\nEnter the two numbers that you wish to multiply.”);
printf(“\n”);
printf(“\nEnter first number:”);
scanf(“%i”, &x);
printf(“\nEnter second number:”);
scanf(“%i”, &y);
for (counter = 0; counter < y; counter = counter + 1)
{
result = result + x;
}
printf(“\nThe result is %i”, result);
return 0;
}