Şimdi Ara

Program örnekleri-çözüm bekleniyor-yeni

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
9
Cevap
0
Favori
237
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • İngilizce açıklamalı bir programa dökmek istenilen bir problem var bunun bir kısmını yaptım onu ikinci postta vereceğim burda average = sum / 5; anlayamadım

    quote:

    There are 10 students in a class. Each student has taken five tests, and each test is worth 100 points. We want to design an algorithm to calculate the grade for each student, as well as the class average. The grade is assigned as follows: If the average test score is greater than or equal to 90, the grade is A; if the average test score is greater than or equal to 80 and less than 90, the grade is B; if the average test score is greater than or equal to 70 and less than 80, the grade is C; if the average test score is greater than or equal to 60 and less than 70, the grade is D; otherwise, the grade is F. Note that the data consists of students’ names and their test scores.
    (burda average ile detay anlatılıyor uğraşıyorum hala)
    This is a problem that can be divided into subproblems as follows: There are five tests, so you design an algorithm to find the average test score.Next,you design an algorithm to determine the grade. The two subproblems are to determine the average test score and to determine the grade.

    Let us first design an algorithm to determine the average test score. To find the average test score, add the five test scores and then divide the sum by 5. Therefore, the algorithm is the following:

    1. Get the five test scores. 2. Add the five test scores. Suppose sum stands for the sum of the test scores. 3. Suppose average stands for the average test score. Then
    average = sum / 5;
    (bu kısmı bir türlü algoritmaya çeviremedim. bu kod hariç istenilenleri yaptım. :/ )

    Next, you design an algorithm to determine the grade. Suppose grade stands for the grade assigned to a student. The following algorithm determines the grade:

    if average is greater than or equal to 90 grade = A otherwise if average is greater than or equal to 80 and less than 90 grade = B otherwise if average is greater than or equal to 70 and less than 80 grade = C otherwise if average is greater than or equal to 60 and less than 70 grade = D otherwise grade = F

    You can use the solutions to these subproblems to design the main algorithm as follows: (Suppose totalAverage stands for the sum of the averages of each student’s test average.)
    1. totalAverage = 0; 2. Repeat the following steps for each student in the class:
    a. Get student’s name. b. Use the algorithm as discussed above to find the average test score.
    c. Use the algorithm as discussed above to find the grade. d. Update totalAverage by adding the current student’s average test score.
    3. Determine the class average as follows:
    classAverage = totalAverage / 10
    A programming exercise in Chapter 8 asks you to write a C++ program to determine the average test score and grade for each student in a class



    < Bu mesaj bu kişi tarafından değiştirildi berce -- 8 Aralık 2018; 1:18:27 >







  • quote:


    #include <iostream>
    using namespace std;

    int main ()
    {
    char *students[]={"Mehmet","Hakan","Ayse","Mustafa","Ali","Ahmet","Harun","Ozge","Haluk","Salih"};
    //char students[]={'Mehmet','Hakan','Ayse','Mustafa','Ali','Ahmet','Harun','Ozge','Haluk','Salih'};
    int grade[]={96,76,54,40,75,45,85,70,69,100};
    //int sum[]={90,80,70,60,45};
    //int avarge, sum;
    int totalAverage=0, classAverage, i;

    for (i=0; i<10 ; i++)
    {
    cout<<endl //burası cmd ekranında daha düzgün bir görünüm sagliyor.
    <<"Ogrencinin ismi: "<< students << endl
    << " Aldigi not: " << grade<<" " ;
    totalAverage+=grade;
    if (grade >=90)
    {cout<<"grade=A ";}
    if (grade>=80 && grade < 90)
    {cout<<"grade=B ";}
    if (grade>=70 && grade < 80)
    {cout<<"grade=C ";}
    if (grade>=60 && grade < 70)
    {cout<<"grade=D ";}
    if (grade <60)
    {cout<<"grade=F ";}
    classAverage=totalAverage /10;
    }


    //avarge=sum / 5;

    cout<<endl
    <<"Sinif Ortalamasi:"<<classAverage;
    }



    Program örnekleri-çözüm bekleniyor-yeni

    Kod böyle çıktısı resimdeki gibi
    //avarge=sum / 5;
    ekledim ama nasıl kullanacağımı bilmiyorum
    benden beş tane test score eklememi istedi ama ben bir türlü onu diğer avarge ile birleştirmesini yapamadım.




  • Program örnekleri-çözüm bekleniyor-yeni

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

    int main ()
    {
    char *students[10]={"Mehmet","Hakan","Ayse","Mustafa","Ali","Ahmet","Harun","Ozge","Haluk","Salih"};
    //string students[]={'Mehmet','Hakan','Ayse','Mustafa','Ali','Ahmet','Harun','Ozge','Haluk','Salih'};
    int grade[5][10]={
    {96,76,54,40,100,45,85,70,69,100},
    {76,96,70,54,100,70,80,90,75,90},
    {70,65,54,40,85,45,85,65,54,85},
    {86,70,54,40,90,70,90,75,65,90},
    {95,80,54,40,95,75,85,70,69,100},
    };



    double average=0, classAverage, sum=0;
    int i, j;



    for (i=0; i<10 ; i++)
    {
    for (j=0; j<5 ; ++j)
    {
    cout<<endl;
    cout<<"Ogrencinin ismi: "<< students[i] << endl ;
    cout<< " Aldigi not: " << grade[j][i]<<" ";


    //average=sum /5;
    if (grade[j][i] >=90 || grade[j][i]==100)
    {cout<<"grade=A ";}
    if (grade[j][i]>=80 && grade[j][i] < 90)
    {cout<<"grade=B ";}
    if (grade[j][i]>=70 && grade[j][i] < 80)
    {cout<<"grade=C ";}
    if (grade[j][i]>=60 && grade[j][i] < 70)
    {cout<<"grade=D ";}
    if (grade[j][i] <60)
    {cout<<"grade=F ";}
    average+=grade[j][i];
    classAverage=average /5 /10;
    if (j==4)
    {

    cout<<"average: "<<average<<" ";
    }
    }
    }

    cout<<"sum: "<<sum;

    cout<<endl
    <<"Sinif Ortalamasi:"<<classAverage<<" ";
    }


    Belki zorlamış gibi olacakta ben uğraşmasını severim.
    eğer bu average her 5 not için hesaplamasını bulabilirsem işlem tamam oluyor.
    birde bunun class şekli varda(araştırma halindeyim.) ben array ile bunu yapabilir miyim? diye merak ediyorum

    senden ricam bir el atsan problemi kurdum. şöyle: öğrencilerin aldığı 5 notdan sonra eklenmeyecek yeniden hesaplanacak

    average+=grade[j]; bunu nasıl her öğrencinin beş notu için nasıl düzenleyebilirim. zannederim sorun burda

    not:avarge 5'e bölmedim ki toplamını bir göreyim diye onun class average ekledim



    < Bu mesaj bu kişi tarafından değiştirildi berce -- 27 Kasım 2018; 1:7:1 >




  •  
    #include <iostream>
    #include <string>
    #include <array>
    //#include <cstdlib>
    #include <exception>
    #include <memory>
    using namespace std;

    struct students {
    string name;
    int grade[5];
    double sum;


    }stu;
    int main () {
    int i,t,k, l;
    double totalAverage=0, average, classAverage;
    char option;
    struct students student[10];
    // struct students *ptr;
    // ptr=student;
    student[0].name="Mehmet";
    student[1].name="Mustafa";
    student[2].name="Hakan";
    student[3].name="Ayşe";
    student[4].name="Ali";
    student[5].name="Ahmet";
    student[6].name="Harun";
    student[7].name="Özge";
    student[8].name="Haluk";
    student[9].name="Salih";
    student[0].grade[0]=96; student[1].grade[0]=76; student[2].grade[0]=54; student[3].grade[0]=85; student[4].grade[0]=100;
    student[0].grade[1]=45; student[1].grade[1]=85; student[2].grade[1]=70; student[3].grade[1]=90; student[4].grade[1]=100;
    student[0].grade[2]=90; student[1].grade[2]=96; student[2].grade[2]=70; student[3].grade[2]=90; student[4].grade[2]=100;
    student[0].grade[3]=70; student[1].grade[3]=80; student[2].grade[3]=90; student[3].grade[3]=95; student[4].grade[3]=90;
    student[0].grade[4]=85; student[1].grade[4]=65; student[2].grade[4]=65; student[3].grade[4]=100; student[4].grade[4]=85;

    student[5].grade[0]=96; student[6].grade[0]=45; student[7].grade[0]=85; student[8].grade[0]=65; student[9].grade[0]=85;
    student[5].grade[1]=76; student[6].grade[1]=86; student[7].grade[1]=70; student[8].grade[1]=54; student[9].grade[1]=90;
    student[5].grade[2]=54; student[6].grade[2]=70; student[7].grade[2]=90; student[8].grade[2]=75; student[9].grade[2]=90;
    student[5].grade[3]=40; student[6].grade[3]=95; student[7].grade[3]=80; student[8].grade[3]=54; student[9].grade[3]=95;
    student[5].grade[4]=100; student[6].grade[4]=75; student[7].grade[4]=85; student[8].grade[4]=70; student[9].grade[4]=100;
    liste:cout<<"Listeden işlemi seçiniz: "<<endl;
    cout <<"1. İstenilen öğrencinin notlarını ve ortalamasını gör."<<endl;
    cout <<"2. Sınıfın ortalmasını ve toplam ortalamayı gör."<<endl;
    cout<<"Seçiminiz: ";
    cin>>option;
    while ((option != '1') && (option != '2'))
    {
    cout<<"Yanlış seçim yaptınız. Tekrar tuşlayınız: ";
    cin>>option;
    }

    switch (option)
    {
    case '1':
    goto grade_topla;
    case '2':
    goto sinif_ort;
    }

    grade_topla:
    cout << "Sınıfın Öğrencileri: "<<endl;
    for (i=0; i<10; ++i)
    {
    cout<< i+1<< ". "<< student[i].name << " ";
    }
    cout<<endl<<"Öğrencinin not ve ortalamasını görmek için sıra numarasını girin: ";
    cin>>t;
    average1:if ( t<=10)
    {
    for (t, l=0; l<5; l++)
    {
    student[t-1].sum+=student[t-1].grade[l];
    }
    average=student[t-1].sum/5;
    cout<<endl<<"Notları: ";

    for (t, i=0; i<5; ++i)
    {
    cout<<student[t-1].grade[i]<<" ";
    if (student[t-1].grade[i] >=90 || student[t-1].grade[i] ==100)
    {cout<<"grade=A ";}
    if (student[t-1].grade[i] >=80 && student[t-1].grade[i] < 90)
    {cout<<"grade=B ";}
    if (student[t-1].grade[i] >=70 && student[t-1].grade[i] < 80)
    {cout<<"grade=C ";}
    if (student[t-1].grade[i] >=60 && student[t-1].grade[i] < 70)
    {cout<<"grade=D ";}
    if (student[t-1].grade[i] <60)
    {cout<<"grade=F ";}
    }
    cout<<endl<<student[t-1].name<<" İsimli öğrencinin aldığı ortalama: "<<average<<" " ;
    secim1:cout<<endl<<"Başka işlem yapmak ister misiniz? Evet için 1, Hayır için 2 tuşlayınız. ";
    cout<<endl<<"Seçiminiz: ";
    cin>>option;
    switch (option)
    {
    case '1':
    goto liste;
    case '2':
    exit(0);
    }

    return 0;

    }
    else
    {
    while (t>10)
    {
    cout<<"Sıra numarası bulunamadı. Tekrar Deneyiniz: ";
    cin>>t;
    goto average1;
    }
    return 0;
    }


    sinif_ort:cout<<" Toplam Ortalama: ";
    for (k=0; k<5; ++k)
    {
    student[0].sum+=student[0].grade[k];
    student[1].sum+=student[1].grade[k];
    student[2].sum+=student[2].grade[k];
    student[3].sum+=student[3].grade[k];
    student[4].sum+=student[4].grade[k];
    student[5].sum+=student[5].grade[k];
    student[6].sum+=student[6].grade[k];
    student[7].sum+=student[7].grade[k];
    student[8].sum+=student[8].grade[k];
    student[9].sum+=student[9].grade[k];
    totalAverage=(student[0].sum/5)+(student[1].sum/5)+student[2].sum/5+student[3].sum/5+student[4].sum/5+student[5].sum/5+student[6].sum/5+student[7].sum/5+student[8].sum/5+student[9].sum/5;

    }
    /*
    for (int i=0,l=0; i<10, l<10; ++i,++l)
    {
    for (k=0; k<5; ++k)
    {
    student[i].sum+=student[l].grade[k];
    totalAverage+=(student[i].sum);

    }
    } */


    cout<<totalAverage<<" ";
    classAverage=(totalAverage)/10;
    cout << "Sınıf Ortalaması: " << classAverage<<" ";

    if (classAverage >=90 || classAverage ==100)
    {cout<<"grade=A ";}
    if (classAverage >=80 && classAverage < 90)
    {cout<<"grade=B ";}
    if ( classAverage >=70 && classAverage < 80)
    {cout<<"grade=C ";}
    if (classAverage >=60 && classAverage < 70)
    {cout<<"grade=D ";}
    if ( classAverage <60)
    {cout<<"grade=F ";}
    goto secim1;
    }




    goto secim1; dediğim zaman yani seçim1 git denildiğinde her sorguda classAverage ve totalAverage average değerlerinde sürekli artış oluyor.Program örnekleri-çözüm bekleniyor-yeni
    ilk çalışıtrıdığımda ortalamalayı doğru veriyor. ama tekrar seçim yap denildiğinde hata ile karşılaşıyorum.
    birde

    quote:

     
    for (k=0; k<5; ++k)
    {
    student[0].sum+=student[0].grade[k];
    student[1].sum+=student[1].grade[k];
    student[2].sum+=student[2].grade[k];
    student[3].sum+=student[3].grade[k];
    student[4].sum+=student[4].grade[k];
    student[5].sum+=student[5].grade[k];
    student[6].sum+=student[6].grade[k];
    student[7].sum+=student[7].grade[k];
    student[8].sum+=student[8].grade[k];
    student[9].sum+=student[9].grade[k];
    totalAverage=(student[0].sum/5)+(student[1].sum/5)+student[2].sum/5+student[3].sum/5+student[4].sum/5+student[5].sum/5+student[6].sum/5+student[7].sum/5+student[8].sum/5+student[9].sum/5;}


    bu for içindeki kodu daha kısa yazmaya çalıştım fakat bilgisayar kısa kodu işlediğinde sürekli yüksek rakamlar veriyordu çareyi böyle yazmakta buldum. örneğin

    student[0].sum+=student[0].grade[k]; içersinde grade[k] beş testi de ekledikten sonra stundent[1] geçecek bunu nasıl algoritmaya dökebilirim.

    inşallah şimdi bakmaya bir engel yoktur.




  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.