How to change conio.h?

Apr 16, 2013 at 8:24am
/* The use of arrays (in class / in the main program).
Arrays in the main program is also known as an object array. */

#include <iostream>
#include <cstring>
#include <conio.h> //How to change conio.h?
using namespace std;

class STUDENT
{
private:
char name[30][35]; // 30 long names; each names is 35 letters
//char-type; 2-D array
long kpitm[30];
int bhgn[30];
double cgpa[30], cgpaMin, cgpaMax ;
public:
void setData( );
void CalTotalCGPA( );
void CalBilAvg( );
void cgpaMin( );
void cgpaMax( );
void displayData( );
};

void STUDENT :: setData( )
{
for (int bil = 0; bil < 30; bil++)
{
cout << “\n Fill-in student’s name:”;
cin >> ws;
cin.getline(name[bil], 34);
cout << “\n Fill-in kpitm number:”;
cin >> kpitm[bil];
cout << “\n Fill-in section:”;
cin >> bhgn[bil];
cout << “\n Fill-in CGPA :”;
cin >> cgpa[bil];
}
}

void STUDENT :: CalTotalCGPA( )
{
double totalcgpa = 0;
for (int bil = 0; bil < 30; bil++)
{
totalcgpa = totalcgpa + cgpa[bil];
}
average = totalcgpa/30;
}

void STUDENT :: CalBilAvg( )
{
int bilpelajar = 0;
for (int bil = 0; bil < 30; bil++)
{
if (cgpa[bil] > average)
bilpelajar++;
}
}

void STUDENT :: cgpaMin( )
{
double cgpaMin = cgpa[0]; //cgpaMin = 9999
for (int bil = 1; bil < 30; bil++)
{
if (cgpa[bil] < cgpaMin)
cgpaMin = cgpa[bil];
else
cgpaMin = cgpaMin;
}
}

void STUDENT :: cgpaMax( )
{
double cgpaMak = cgpa[0];//cgpaMax = -9999
for (int bil = 1; bil < 30; bil++)
{
if ( cgpa[bil] > cgpaMax)
cgpaMax = cgpa[bil];
else
cgpaMax = cgpaMax;
}
}

void STUDENT :: displayData( )
{
cout << “Name StudentNo Section CGPA” << endl;
for ( int bil = 0; bil < 30;bil++)
{
cout << name[bil] << “\t\t\t” << kpitm[bil] << “\t\t” << bhgn[bil] << “\t\t” << cgpa[bil] << endl;
}
cout << “Total CGPA of all students is:” << totalcgpa << endl;
cout << “CGPA average is:” << average << endl;
cout << “Total number of students who get more than average CGPA is:” << bilpelajar << endl;
cout << “Min CGPA is:” << cgpaMin << endl;
cout << “Max CGPA is:” << cgpaMax << endl;
}

void main( )
{
STUDENT CS, DIA, DIS;
CS. setData( );
CS. CalTotalCGPA( );
CS. CalBilAvg( );
CS. cgpaMin( );
CS.cgpaMax( );
clrscr( );
CS. displayData( );

DIA.setData( );
DIA.CalTotalCGPA( );
DIA.CalBilAvg( );
DIA.cgpaMin( );
DIA.cgpaMax( );
clrscr( );
DIA.displayData( ):

DIS.setData( );
DIS.CalTotalCGPA( );
DIS.CalBilAvg( );
DIS.cgpaMin( );
DIS.cgpaMax( );
clrscr( );
DIS.displayData( );
}
Apr 16, 2013 at 8:35am
conio.h is probably a file. To change it you can try open it in a text editor, make the changes you want to make and save it.
Apr 16, 2013 at 8:44am
why would you want to change a header file ?
Apr 16, 2013 at 8:49am
Conio.h is a third-party header file, containing definitions that are necessary to use other 3rd-party libraries.

Changing the contents of that file would be a PHENOMENALLY BAD IDEA, unless you have access to all the code of those libraries so that you can rebuild them with the modified header.
Last edited on Apr 16, 2013 at 8:49am
Apr 16, 2013 at 8:57am
> How to change conio.h?

Easy, for this particular program.

1. Just comment out or delete // #include <conio.h>

2. Write a function:
1
2
inline void clrscr( int page_size = 20 ) 
{ for( int i = 0 ; i < page_size ; ++i ) std::cout << '\n' ; }


Last edited on Apr 16, 2013 at 8:59am
Apr 16, 2013 at 2:55pm
Er, how to include that function in my coding? ^ ^
Apr 16, 2013 at 4:01pm
> how to include that function in my coding?

Just write the function and use it.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

inline void clrscr( int page_size = 20 ) 
{ for( int i = 0 ; i < page_size ; ++i ) std::cout << '\n' ; }

int main()
{
   // write some stuff to stdout
   for( int i = 0 ; i < 10 ; ++i ) std::cout << "something\n" ;
   
   // clear up the clutter by simulating clearing of the screen
   std::cout << "hit enter to clear the screen ... " ;
   std::cin.get() ; 
   clrscr() ;
   
   std::cout << "hello without the clutter\n" ;
}
Topic archived. No new replies allowed.