2016-12-14 3 views
-2

Ich versuche, meinen Bildschirm in C++ zu löschen, aber ich diesen Code nicht kompilieren ...Warum bekomme ich Fehler in clrscr(); es sagt undefiniert?

#include<iostream> 
using namespace std; 
#include<conio.h> 

#include<stdio.h> 

class cpuschedule 
{ 
    int n, bu[20]; 

    float twt, awt, wt[20], tat[20]; 

public: 

    void Getdata(); 

    void fcfs(); 

    void sjf(); 

    void roundrobin(); 

}; 

//Getting no of processes and Burst time 

void cpuschedule::Getdata() 
{ 
    int i; 

    cout << "Enter the no of processes : "; 

    cin >> n; 

    for (i = 1; i <= n; i++) 
    { 
     cout << "\nEnter The BurstTime for Process p"<< i << " = "; 

     cin >> bu[i]; 
    } 

} 

//First come First served Algorithm 

void cpuschedule::fcfs() 
{ 
    int i, b[10]; 

    float sum = 0.0; 

    twt = 0.0; 

    for (i = 1; i <= n; i++) 
    { 
     b[i] = bu[i]; 

     cout << "\nBurst time for process p"<< i << " = "; 

     cout << b[i]; 
    } 

    wt[1] = 0; 

    for (i = 2; i <= n; i++) 
    { 
     wt[i] = b[i - 1] + wt[i - 1]; 
    } 

    for (i = 1; i <= n; i++) 
    { 
     twt = twt + wt[i]; 

     tat[i] = b[i] + wt[i]; 

     sum += tat[i]; 
    } 

    awt = twt/n; 
    sum = sum/n; 

    cout << "\nTotal Waiting Time = " << twt; 

    cout << "\nAverage Waiting Time = " << awt; 

    cout << "\nAverage Turnaround time = " << sum; 

} 

//Shortest job First Algorithm 

void cpuschedule::sjf() 
{ 

    int i, j, temp, b[10]; 

    float sum = 0.0; 

    twt = 0.0; 

    for (i = 1; i <= n; i++) 
    { 
     b[i] = bu[i]; 

     cout << "\nBurst time for process p" << i << " = "; 

     cout << b[i]; 
    } 

    for (i = n; i >= 1; i-) 
    { 
     for (j = 2; j <= n; j++) 
     { 
      if (b[j - 1]>b[j]) 
      { 
       temp = b[j - 1]; 

       b[j - 1] = b[j]; 

       b[j] = temp; 
      } 
     } 
    } 

    wt[1] = 0; 

    for (i = 2; i <= n; i++) 
    { 
     wt[i] = b[i - 1] + wt[i - 1]; 
    } 

    for (i = 1; i <= n; i++) 
    { 
     twt = twt + wt[i]; 

     tat[i] = b[i] + wt[i]; 

     sum += tat[i]; 
    } 

    awt = twt/n; 
    sum = sum/n; 

    cout << "\nTotal Waiting Time = " << twt; 

    cout << "\nAverage Waiting Time = " << awt; 

    cout << "\nAverage turnaround time = " << sum; 
} 

//Round Robin Algorithm 

void cpuschedule::roundrobin() 
{ 
    int i, j, tq, k, b[10], Rrobin[10][10], count[10]; 

    int max = 0; 

    int m; 

    float sum = 0.0; 

    twt = 0.0; 

    for (i = 1; i <= n; i++) 
    { 
     b[i] = bu[i]; 

     cout << "\nBurst time for process p" << i << " = "; 

     cout << b[i]; 

     if (max<b[i]) 

      max = b[i]; 

     wt[i] = 0; 
    } 

    cout << "\nEnter the Time Quantum = "; 

    cin >> tq; 

    //TO find the dimension of the Round robin array 

    m = max/tq + 1; 

    //initializing Round robin array 

    for (i = 1; i <= n; i++) 
    { 
     for (j = 1; j <= m; j++) 
     { 
      Rrobin[i][j] = 0; 
     } 
    } 

    //placing value in the Rrobin array 

    i = 1; 

    while (i <= n) 
    { 
     j = 1; 

     while (b[i]>0) 
     { 
      if (b[i] >= tq) 
      { 
       b[i] = b[i] - tq; 

       Rrobin[i][j] = tq; 

       j++; 
      } 
      else 
      { 
       Rrobin[i][j] = b[i]; 

       b[i] = 0; 

       j++; 
      } 
     } 

     count[i] = j - 1; 

     i++; 
    } 

    cout <<" Display"; 

    for (i = 1; i <= n; i++) 
    { 
     for (j = 1; j <= m; j++) 
     { 
      cout << "\nRr[" << i << ", " << j << "] = " << Rrobin[i][j]; 

      cout << "  "; 
     } 
     cout << "\ncount = " << count[i]; 
    } 

    for (j = 1; j <= n; j++) 
    { 
     for (i = 1; i <= count[j]; i++) 
     { 
      if (i == count[j]) 
      { 
       for (k = 1; k<j; k++) 
       { 
        if (k != j) 

         wt[j] += Rrobin[k][i]; 
       } 
      } 

      else 

      for (k = 1; k <= n; k++) 
      { 

       if (k != j) 

        wt[j] += Rrobin[k][i]; 
      } 
     } 
    } 

    for (i = 1; i <= n; i++) 
     cout << "\nWaiting Time for process P" << i << " = " << wt[i]; 

    //calculating Average Weighting Time 

    for (i = 1; i <= n; i++) 
    { 
     twt = twt + wt[i]; 

     tat[i] = b[i] + wt[i]; 

     sum += tat[i]; 
    } 

    awt = twt/n; 
    sum = sum/n; 

    cout << "\nTotal Waiting Time = " << twt; 

    cout << "\nAverage Waiting Time = " << awt; 

    cout << "\nAverage turnaround time = " << sum; 

} 

void main() 
{ 
    int ch = 0, cho; 

    cpuschedule c; 

    clrscr(); 

    do 
    { 
     switch (ch) 
     { 

     case 0: 

      cout << "\n0.MENU"; 

      cout << "\n1.Getting BurstTime"; 

      cout << "\n2.FirstComeFirstServed"; 

      cout << "\n3.ShortestJobFirst"; 

      cout << "\n4.RoundRobin"; 

      cout << "\n5.EXIT"; 

      break; 

     case 1: 
      c.Getdata(); 
      break; 

     case 2: 
      cout << "FIRST COME FIRST SERVED SCHEDULING"; 

      c.fcfs(); 
      break; 

     case 3: 
      cout << "SHORTEST JOB FIRST SCHEDULING"; 
      c.sjf(); 
      break; 

     case 4: 
      cout << "ROUND ROBIN SCHEDULING"; 
      c.roundrobin(); 
      break; 

     case 5: 
      break; 

     } 

     cout << "\nEnter your choice : "; 

     cin >> ch; 

     getch(); 

    } while (ch<5); 
} 

Hier ist der Compiler-Fehler:

clrscr is undefined

+7

'clrscr()' ist keine Standard-C++ - Funktion. –

+0

Welche andere Funktion kann ich verwenden? – Gab

+3

Es gibt keine Standardmethode zum Löschen des Bildschirms. Es hängt davon ab, welche Entwicklungsumgebung, Bibliotheken usw. Sie haben. Sie müssen etwas herausfinden. Wenn alles andere fehlschlägt, können Sie viele 'printf (" \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n ");' sortieren, um den Bildschirm zu "löschen". –

Antwort

0

ich ein kleines Beispiel kodiert Sie. Ich gehe davon aus, dass Sie auf Windows laufen.

#include <iostream> 
#include <string> 
using namespace std; 

#include <stdio.h> // include this for the clear 

int main() 
{ 
    string usersInput; 
    cout <<"Enter string: "; 
    getline(cin,usersInput); 

    cout << "The string is: " << usersInput << endl; 

    cout << "Press Enter to clear screen."; 

    cin.ignore(); 
    system("CLS"); // this clears the screen 

    cin.ignore(); 
    return 0; 
} 
+0

_Note_: Auf _Ux_, anstelle von [CLS] (http://ss64.com/nt/cls.html) können Sie [clear] (https://linux.die.net/man/1/clear) (es gibt andere Wege oder Befehle, aber das scheint die einfachste zu sein). – CristiFati

+0

@CristiFati Ich habe nie C++ unter Unix/Linux codiert. Brauchen Sie eine Header-Datei für clear()? – asmcriminal

+0

_clear_ ist das Gegenstück von _CLS_: es ist ein Shell-Befehl, also rufst du es ähnlich wie _C_/_C++ _ auf (wie bei _CLS_: über 'system'). – CristiFati

Verwandte Themen