Create a structure called employee that contains 2 members: an employee number(int type) and the employee’s compensation(type float). Ask the user to fill in this data for 3 employees, store it in 3 variables of type struct employee and then display the information for each employee. Use a separate display function for the information display. Write a program to create a structure for students to get the details of N students and when user inputs a student name it must print the details of only that student. Hint: Create Array of Objects using dynamic memory allocation
Object Oriented Programming Lab Manual 4 Instructor: Ayesha Liaqat Email:
[email protected] Department of computer Science National University of Computer and Emerging Sciences mailto:
[email protected] Objective: Structures Structures with arrays Nested Structures Structures with functions Structures with pointers and DMA Create a structure called employee that contains 2 members: an employee number(int type) and the employee’s compensation(type float). Ask the user to fill in this data for 3 employees, store it in 3 variables of type struct employee and then display the information for each employee. Use a separate display function for the information display. Write a program to create a structure for students to get the details of N students and when user inputs a student name it must print the details of only that student. Hint: Create Array of Objects using dynamic memory allocation Write a program that declares a structure based on the figure given below. This time you will declare three instances of the entity student and initialize the three instances with the data shown in the table below. you have to find the total marks of the students in all of the students instances. Within the body of the main function do the following: Declare three instances of the student structure student s1,s2,s3 Initialize each of these instances with the data shown in the table Access the course marks of each instance step by step and add them all together and save the result in a new integer named totalMarks. Display the total marks of the student at the end of the program. PROBLEM NO.1 PROBLEM NO.2 PROBLEM NO.3 Write a program to define a structure “employee” that has the following members. Emp_no, basic_pay, house_rent, medical_allow, conveyance_allow, net_pay Declare the structure variable “emp”, enter values to its members „emp_no‟ & „basic_pay‟. Compute the allowances based on basic pay and compute net pay and print on the screen. Allowances are computed as: House rent is 45% of the basic pay. Medical Allowance is 5% of the basic pay. Conveyance allowance is 10% of the basic pay. Your goal in this problem is to define and use the structure(s) to store semester registration information for students at FAST. A semester registration consists of a semester code, and course registrations of between one and five courses. A course registration consists of course code, course title, credit hours, section, and repeat count. Create a four- function calculator for fractions using structure. Program should store the numerator and denominator of two fractions before operating them. Make a structure named fraction, whose members are nominator and denominator of type int. All fractions related data should be stored in structures of this type. Here are the formulas for the four automatic operations applied in fractions. Addition: a/b + c/d = (a*d + b*c) / (b*d) Subtraction: a/b - c/d = (a*d - b*c) / (b*d) Multiplication: a/b * c/d = (a*c) / (b*d) Division: a/b / c/d = (a*d) / (b*c) Input should look like this: Enter first fraction: ½ Enter Second Fraction: 2/5 Enter Operand: + Output: Answer is: 9/10 write a program to help a University system to store records for its employee. you have to perform the following task: Define a struct facultyMember with the following attributes: PROBLEM NO.4 PROBLEM NO.5 PROBLEM NO.6 PROBLEM NO.7 ID number first name last name designation e.g… assistant professor, lecturer etc… Implement a function void newrecord(facultyMember &fm) which will take an argument of facultyMember type, input values for all the attributes from user and store it in the argument variable. Implement a function void printdetails(facultyMember fm) which will print the values of the variable fm passed as an argument Implement your main(). Declare a variable of facultyMember type, assign values to it using newrecord function. Print its values using printdetails function. Now declare a facultyMember type array of size 3 in main(). Fill the values using newrecord function (Note that you are newrecord can assign values to a single faculty member and you cannot change the prototype.) Print the values of the above array using printdetails function without changing the prototype Implement a functions void sort id which takes a faculty member type array as an argument and its maximum size. you have to sort the array in ascending order with respect to the ID number (Use any sorting algorithm). Be careful while swapping the two locations of the array Create a student database of Students using a structs. Your program will have two structures One for sections and One for Students. A student will have the following attributes: 1. Name 2. CNIC 3. Gender PROBLEM NO.8 4. CGPA And the struct section will the following attributes: 1. An array of students less than 40. 2. Section name 3. Class teacher. You have to write an efficient program to create sections of the amount user wants to, with less than 40 students. If the array of students is full, offer the student another section. Student can update their attributes. Display the students of the whole section on request. Sort the students wrt their CGPA. Write a menu driven program to complete all the required functionalities. Write a C++ program for the following problem: Write a program that declares a struct to store the data of a baseball player (player’s name, number of home runs, and number of hits). Declare an array of 10 components to store the data of 10 baseball players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of a specific player, and update the data of a player. (You may assume that input data is stored in a file.) Before the program terminates, give the user the option to save data in a file. Your program should be menu driven, giving the user various choices. Pointer to structure, Structure variable array, dynamic memory allocation) Assuming that a text file named “myfile.txt” contains matrix of any size, write a program that reads matrix from the file and count the number of rows and columns of the matrix. Then print the matrix, number of rows and columns on the console. For example text file contain the following matrix Output will something like this Number of rows: 4 Number of columns: 3 PROBLEM NO.9 PROBLEM NO.10