In this ques , background of q.49 was too required, but chill. I did what this question asked, even more than that :)
Note : after executing this program into your machine, delete the file "outputFile.txt" in same directory each time for unambiguidity of each run.
In the program, I have taken input of both students in array "object" and then wrote their contents in file "outputFile.txt".
And displayed the details of both students (i) first from file by read mode (ii) using our struct array
I have attached image of output (an example, that will help you )
// c++ code starts here
#include <iostream>
#include <fstream>
using namespace std;
struct Student {
char name[20];
int age, marks;
};
// Function definition of input() to input info
void inputToFile(Student obj)
{
ofstream file; // Object to write in file
file.open("outputFile.txt", ios::app);
// Writing the object's data in file
file.write((char*)&obj, sizeof(obj));
file.close();
}
void outputFromFile()
{
// Object to read from file
ifstream file;
file.open("outputFile.txt", ios::in); // Opening file in input mode
// Object of class contestant to input data in file
Student obj;
// Reading from file of student 0 into object "obj"
file.read((char*)&obj, sizeof(obj));
cout<<"Details of 0th student from file : \n";
cout<<"Name = "<<obj.name<<endl;
cout<<"Age = "<<obj.age<<endl;
cout<<"Marks = "<<obj.marks<<endl;
// Reading from file of student 1 into object "obj"
file.read((char*)&obj, sizeof(obj));
cout<<"Details of 1st student from file : \n";
cout<<"Name = "<<obj.name<<endl;
cout<<"Age = "<<obj.age<<endl;
cout<<"Marks = "<<obj.marks<<endl<<endl;
}
// Driver code
int main()
{
Student object[2]; //object is our struct array
for(int i=0;i<2;++i){
cout<<"Enter details of "<<i<<"th student : "<<endl;
cout<<"Name : ";
cin>>object[i].name;
cout<<"Age : ";
cin>>object[i].age;
cout<<"Marks : ";
cin>>object[i].marks;
cout<<endl;
}
//writing details of first student in file
inputToFile(object[0]);
//writing details of second student in file
inputToFile(object[1]);
//outputting details of both studs through file
outputFromFile();
//outputting details of both students from object array
for(int i=0;i<2;++i){
cout<<"Details of "<<i<<"th student from object array : \n";
cout<<"Name is "<<object[i].name<<endl;
cout<<"Age is "<<object[i].age<<endl;
cout<<"Marks is "<<object[i].marks<<endl;
}
return 0;
}
// output

//image for indentation knowledge
![#include <iostream> #include <fstream> using namespace std; struct Student { char name[20]; int age, marks; }; // Function de](http://img.homeworklib.com/questions/fcb2d6b0-bf25-11eb-8fa7-114bc2922ad9.png?x-oss-process=image/resize,w_560)
if any query, ask on comment section. if more improvise needed, provide with Q.49 details
And if you understood this, please do upvote.
Regards ^_^
c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...
Registration Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration”...
In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...
I am reading a text file and trying to store the information into an array so I can use this in different parts of my program. So a dynamic array. So far I have been able to retrieve the information from the text file and organize it by category (User name,User ID, User password) I am having troubles allocating an array and storing the information correctly. Since I have different data types (int, string) do I need to create a...
Create a C# program that will first prompt the instructors to enter the number of students they currently have in their classes. Use this value for the size of the row dimension of your multidimensional array. Next, prompt the instructors to type in the number of scores they would like to enter. This variable will be used to designate the column size dimension of your multidimensional array. Then, use a loop to prompt the user to enter the number of...
Program in C Student Data using Structs In this assignment you will create a program (using multiple .c files) to solve the following problem: You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data: struct Student{ char name[50]; int id; float...
PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...
Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...
C
program
Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...
3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16 marks] (b) Consider the following code fragments: If a = 10; Evaluate the new value of “b” in the following: (i) b = ++ a; (ii) b = a ++; What value would a and b store in (i) and (ii) after program execution? [4 marks] 4. Create a C++ program that makes use of three arrays; name, mark, grade. The program should accept...