Pointers, need opinions
Apr 19, 2014 at 9:35am UTC
Hi guys~
so i got this assignment that wants me to create a program using File I/O and Pointers
so me & my friend have created this exam results program..File I/o part is good..but we still don't know where to put the pointers..in your opinion, which part in this code can i put pointers and how?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
// 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;
}
void intro(){
cout << "\n\n\n\n\n\n\n" ;
cout << "\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" ;
cout << "\t* Welcome To Student Exam Information System *\n" ;
cout << "\t* *\n" ;
cout << "\t* This Program Developed By *\n" ;
cout << "\t* Iqmal Azim & Khairul Aiman *\n" ;
cout << "\t* Press Enter Button To Continue.. *\n" ;
cout << "\t* *\n" ;
cout << "\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" ;
cin.get();
}
void about(){
cout << "==============================================================================" << endl;
cout << "This program will help you to calculate the student GPA base on the input data" << endl;
cout << "==============================================================================" << endl;
cout << "" << endl;
cout << "" << endl;
cout << "The data has been calculated" << endl;
cout << "Please open the file name Student Exam Information....." << endl;
cout << "" << endl;
}
Topic archived. No new replies allowed.