स्यूडोकोड जांच। कार्य के लिए मान्यता की जरूरत है

वोट
5

मैं पहले से ही तो तुम मुझे धोखा की मदद नहीं की जाएगी में यह कर दिया है। बस सोच रहा है कि अगर यह सही लग रहा है:

काम: इनपुट कर्मचारी के नाम और वेतन की एक सूची है, और मतलब (औसत) वेतन के साथ-साथ ऊपर और नीचे मतलब वेतन की संख्या का निर्धारण।

योजना: नाम और वेतन के इनपुट की अनुमति दें गणना मीन क्रमबद्ध मान की गणना मीन ऊपर मूल्यों मीन नीचे मान गणना

//This program will allow a user to input an employee name and salary
//The output will contain the mean salary 
//as well as the number of salaries above and below the mean
//
//Arrays Used:
//Name(K) = Array for employee names
//Salary(K) = Array for salaries
//
//Variables Used:
//Mean = Mean of all employees Salaries
//UpMean = Number of Employees making more than the mean
//DwnMean = Number of Employees making less than the mean
//Sum = Sum of all salaries
//CountM = Counter for Mean
//CountUp = Counter for # of salaries above mean
//CountDwn = Counter for # of salaries below mean

Main
    Call WelcomeMessage
    Call InputData
    Call Calculate
    Call OutputData
End Program

WelcomeMessage
    Write, “Beginning the Salary Program” 
End WelcomeMessage

InputData
    Declare Name(100) Of Strings
    Declare Salary(100) Of Real
    Declare Mean, UpMean, DwnMean As Real
    Set Sum = 0
    Set CountM = 0
    Set CountUp = 0
    Set CountDwn = 0
    Write, Enter Employee name and Salary.
    Write, Enter *,0 when done.
    Input Name(K), Salary(K)
    While Name(K) <> *
        Set CountM = CountM + 1
        Set Sum = Sum + Salary
        Write, Enter Employee name and Salary.
        Write, Enter *,0 when done.
        Input Name(K), Salary(K)
    End While
End InputData

Calculation
    //Here Mean is found
    Set Mean = Sum / CountM
    //Here Number of Employees making more than the mean is found
    For K = Step 1 to CountM
        If Salary(K) > Mean Then
            Set CountUp = CountUp + 1
        End If
    //Here Number of Employees making more than the mean is found
    Set CountDwn = CountM - CountUp
    //The above algorythm doesn't account for the possibility 
    //of someone making exactly the average so subtract 1 to reconcile
    If Salary(K) = Mean Then
            Set CountDwn = CountDwn - 1
    End If
End Calculation

OutputData
    Write, There were,  CountM, salaries entered.
    Write, The mean salary is:, Mean
    Write, There are, CountUp, employees who make more than the average
    Write, There are, CountDwn, employees who make less than the average
End OutputData
12/06/2009 को 00:02
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


3 जवाब

वोट
5

ठीक लग रहा है। केवल एक चीज मैं सुझाव है, नाम / salery के लिए इनपुट को पढ़ने के दौरान एक do-, जबकि संरचना का प्रयोग है। आप देख सकते हैं इससे पहले कि आप पाश शुरू होता है एक ही तर्क है, और पाश में:

Write, "Enter Employee name and Salary."
Write, "Enter *,0 when done."
Input Name(K), Salary(K)

इसके अलावा, छद्म कोड संकलन नहीं होगा, क्योंकि आप की गणना बुला रहे हैं लेकिन नियमित गणना कहा जाता है;)

सुझाव के लिए धन्यवाद। वास्तव में डो-जबकि साथ अभी तक परिचित नहीं। वो कैसा लगता है? मैं हालांकि शायद इनपुट के बारे में कुछ पाश में बदल सकता है लेकिन यकीन है कि कैसे नहीं था चाहिए।

यह कुछ इस तरह दिखाई दे सकता है:

Do 
    Write, "Enter Employee name and Salary."
    Write, "Enter *,0 when done."
    Input Name(K), Salary(K)
    If Name(K) <> "*"
        Set CountM = CountM + 1
        Set Sum = Sum + Salary
    Else
        BreakLoop
    End If
End While (true)

यह वास्तव में एक बड़ा अंतर स्वाद की बात सच है, लेकिन अधिक। व्यक्तिगत रूप से मुझे लगता है कि यह आसान है पढ़ने के लिए, के बाद से कोड इस तरह से कि आप आसानी से महसूस करते हैं कि आप इनपुट कुछ करने वाले हैं इनपुट की जाँच और इनपुट के आधार पर कुछ करने में लिखा है।

आपके जबकि पाश में सेट COUNT मिनट आदि (पाठ प्रवाह में) पहला इनपुट के बाद आते हैं, लेकिन इनपुट के बाकी, जिसका अर्थ है आप पाश के शीर्ष में वापस देखने के लिए यह समझना होगा कि यह पिछले के बाद कुछ करता है से पहले "दौर" पाश में। अब यह सिर्फ एक छोटा सा पाश है, लेकिन अगर यह 30 पंक्तियों लंबा था (भगवान न करे) आप ऊपर स्क्रॉल करने के लिए देखने के लिए क्या हो रहा है होगा। क्या आपको पता है मेरा क्या मतलब है :)

12/06/2009 को 00:12
का स्रोत उपयोगकर्ता

वोट
1

की गणना के बारे में एक नोट CountDwn:

आपका "1 घटाना सामंजस्य करने के लिए" होगा, कैसे बिल्कुल के आधार पर Forपाश कार्यान्वयन भाषा में काम करता है, (क) एक "अघोषित चर" प्रकार त्रुटि उत्पन्न, (ख) त्रुटि एक "सीमा से बाहर सूचकांक", या (ग उत्पन्न ) एक घटाना आईएफएफ पिछले वेतन वास्तव में औसत के बराबर था। (इसके अलावा, अपने कोड एक शामिल नहीं End Forमें Calculationहै, लेकिन मुझे लगता है यह पहली बार के बाद तुरंत किया जाना चाहिए End Ifकि समारोह में।)

की गणना करने के बजाय CountDwnसे CountUp(सब के बाद, हर एक वेतन सकता औसत के बराबर हो), मैं पाश में शामिल करने का सुझाव चाहते हैं:

Calculation
    //Here Mean is found
    Set Mean = Sum / CountM

    For K = Step 1 to CountM
        //Here Number of Employees making more than the mean is found
        If Salary(K) > Mean Then
            Set CountUp = CountUp + 1
        End If

        //Here Number of Employees making less than the mean is found
        If Salary(K) < Mean Then
            Set CountDwn = CountDwn + 1
        End If
    End For
End Calculation

ध्यान दें कि CountUp + CountDwnजरूरी के बराबर नहीं है CountM

12/06/2009 को 00:50
का स्रोत उपयोगकर्ता

वोट
0
FINAL ALGORITHM

START
OUTPUT "Enter the number of parcels"
INPUT NUMBEROFPARCELS
INTEGER PRICE = 0
INTEGER PARCELWEIGHT [1:NUMBEROFPARCELS]
INTEGER TOTALPRICE = 0

FOR PARCELLOOP = 1 TO NUMBEROFPARCELS
    INTEGER REJECT = 0
    INTEGER ACCEPT = 0
    INTEGER ACCEPTWEIGHT = 0
    INTEGER REJECTEDPARCELS = 0

    OUTPUT "Enter the weight of the parcel in kg"
    INPUT WEIGHT
    IF (WEIGHT < 1) THEN
        REJECT = REJECT + 1
        OUTPUT "The weight of the parcel should be atleast 1kg"
    ELSE
        IF (WEIGHT > 10) THEN
            REJECT = REJECT + 1
            OUTPUT "The weight of the parcel should be less than 10kg"
    ENDIF
    IF (WEIGHT > 1) THEN
        IF (WEIGHT < 10) THEN
            PARCELWEIGHT[PARCELLOOP] = WEIGHT
        ENDIF
    ENDIF


    OUTPUT "Enter the first dimension of the parcel in cm"
    INPUT DIMENSION1
    IF (DIMENSION1 > 80 ) THEN
        REJECT = REJECT + 1
        OUTPUT "Each dimension of the parcel should be less than 80"
    ENDIF

    OUTPUT "Enter the second dimension of the parcel in cm"
    INPUT DIMENSION2
    IF (DIMENSION2 > 80 ) THEN
        REJECT = REJECT + 1
        OUTPUT "Each dimension of the parcel should be less than 80"
    ENDIF

    OUTPUT "Enter the third dimension of the parcel in cm"
    INPUT DIMENSION3
    IF (DIMENSION3 > 80 ) THEN
        REJECT = REJECT + 1
        OUTPUT "Each dimension of the parcel should be less than 80"
    ENDIF

    TOTALDIMENSION = DIMENSION1 + DIMENSION2 + DIMENSION3
    IF (TOTALDIMENSION > 200 ) THEN
        REJECT = REJECT + 1
        OUTPUT "The size of the parcel should be less than 200cm"
    ENDIF

    IF (REJECT > 0 ) THEN
        OUTPUT "Your parcel has been rejected for the reasons above"
        REJECTEDPARCELS = REJECTEDPARCELS + 1
    ENDIF

    IF (REJECT = 0)THEN
        OUTPUT "Your parcel has been accepted"
        ACCEPT = ACCEPT + 1 
        ACCEPTWEIGHT = ACCEPTWEIGHT + WEIGHT
    END IF

    INTEGER PARCELSACCEPTED = ACCEPT
    INTEGER TOTALWEIGHT = ACCEPTWEIGHT
    INTEGER PARCELSREJECTED = REJECTEDPARCELS

    OUTPUT "The number of parcels accepted is " PARCELSACCEPTED " and the total weight of the parcels is " TOTALWEIGHT
    OUTPUT "The number of parcels rejected is " PARCELSREJECTED
NEXT PARCELLOOP

FOR PRICELOOP = 1 TO NUMBEROFPARCELS
    IF (PARCELWEIGHT[PARCELLOOP] < 5) THEN
        PRICE = PRICE + 10
        TOTALPRICE = TOTALPRICE +PRICE
    END IF

    IF (PARCELWEIGHT[PARCELLOOP] > 5) THEN
        PRICE = ((PARCELWEIGHT[PARCELLOOP] - 5)*0.10)/100
        TOTALPRICE = TOTALPRICE +PRICE
    END IF

    OUTPUT "The price of the parcel is " PRICE
NEXT PRICELOOP

OUTPUT "The total price of all the parcels is " TOTALPRICE
STOP
13/11/2016 को 04:29
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more