so i got this assignment that wants me to create a program using File I/O and Pointers
so me n friend have created this exam results program..but we still don't know where to put the pointers..want to ask the sifus' opinions in this..in your opinion, which part in this code can i put pointers and how?
CODE
// File Header
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
// Function Prototype
void intro();
void about();
// Main Function
int main()
{
//Declare Variable
//string number[20];
string name[20];
string program[20];
string subject[20],subject1[20],subject2[20],subject3[20];
string ID[20];
double GPA,credit[20],credit1[20],credit2[20],credit3[20],pointer[20],pointer1[20],pointer2[20],pointer3[20];
double loop;
//read and write file
ifstream readData("database.dat");
ofstream writeData("Student Information.txt");
intro();
system("cls");
for (loop = 0; loop<20; loop++)
{
readData>>name[loop]>>ID[loop]>>program[loop]>>subject[loop]>>credit[loop]>>pointer[loop]>>subject1[loop]>>credit1[loop]>>pointer1[loop]>>subject2[loop]>>credit2[loop]>>pointer2[loop]>>subject3[loop]>>credit3[loop]>>pointer3[loop];
GPA = ((credit[loop] * pointer[loop]) + (credit1[loop] * pointer1[loop]) + (credit2[loop] * pointer2[loop]) + (credit3[loop] * pointer3[loop]))/(credit [loop]+credit1[loop]+credit2[loop]+credit3[loop]);
writeData<< "=============================== "<<"Student Information " << loop+1<< " ================================"
<<"\nName: \t\t\t"<<name[loop]<<"\nStudent ID: \t\t"<<ID[loop]<<"\nProgram: \t\t"<<program[loop]
<<"\nSubject: \t\t"<<subject [loop]<<"\nCredit Hour: \t\t"<<credit [loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer [loop]
<<"\nSubject: \t\t"<<subject1[loop]<<"\nCredit Hour: \t\t"<<credit1[loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer1[loop]
<<"\nSubject: \t\t"<<subject2[loop]<<"\nCredit Hour: \t\t"<<credit2[loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer2[loop]
<<"\nSubject: \t\t"<<subject3[loop]<<"\nCredit Hour: \t\t"<<credit3[loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer3[loop]
<<"\nGrade Pointer Average: \t" << fixed << setprecision(2) << GPA << "\n";
}
about();
return 0;
}
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
// Function Prototype
void intro();
void about();
// Main Function
int main()
{
//Declare Variable
//string number[20];
string name[20];
string program[20];
string subject[20],subject1[20],subject2[20],subject3[20];
string ID[20];
double GPA,credit[20],credit1[20],credit2[20],credit3[20],pointer[20],pointer1[20],pointer2[20],pointer3[20];
double loop;
//read and write file
ifstream readData("database.dat");
ofstream writeData("Student Information.txt");
intro();
system("cls");
for (loop = 0; loop<20; loop++)
{
readData>>name[loop]>>ID[loop]>>program[loop]>>subject[loop]>>credit[loop]>>pointer[loop]>>subject1[loop]>>credit1[loop]>>pointer1[loop]>>subject2[loop]>>credit2[loop]>>pointer2[loop]>>subject3[loop]>>credit3[loop]>>pointer3[loop];
GPA = ((credit[loop] * pointer[loop]) + (credit1[loop] * pointer1[loop]) + (credit2[loop] * pointer2[loop]) + (credit3[loop] * pointer3[loop]))/(credit [loop]+credit1[loop]+credit2[loop]+credit3[loop]);
writeData<< "=============================== "<<"Student Information " << loop+1<< " ================================"
<<"\nName: \t\t\t"<<name[loop]<<"\nStudent ID: \t\t"<<ID[loop]<<"\nProgram: \t\t"<<program[loop]
<<"\nSubject: \t\t"<<subject [loop]<<"\nCredit Hour: \t\t"<<credit [loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer [loop]
<<"\nSubject: \t\t"<<subject1[loop]<<"\nCredit Hour: \t\t"<<credit1[loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer1[loop]
<<"\nSubject: \t\t"<<subject2[loop]<<"\nCredit Hour: \t\t"<<credit2[loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer2[loop]
<<"\nSubject: \t\t"<<subject3[loop]<<"\nCredit Hour: \t\t"<<credit3[loop]<<"\nPointer: \t\t"<< fixed << setprecision(2)<<pointer3[loop]
<<"\nGrade Pointer Average: \t" << fixed << setprecision(2) << GPA << "\n";
}
about();
return 0;
}