Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simeon Baltadzhiev
- // 193030
- // 27Б
- // 18.03.2020
- //-------------- Условие----------------------
- //11.
- // За К кандидат-студенти са дадени име, входящ номер и 5 оценки.
- //Да се въведат данните и да се изведат входящите номера и имената на кандидат-студентите
- //със сума на оценките под 12. Да се използват динамични масиви.
- //--------------------------------------------
- #include <iostream>
- #include <stdio.h>
- #include <string>
- #include <string>
- #include <string.h>
- using namespace std;
- struct student {
- char name[30];
- char referenceNum[10];
- int grades[6] = {};
- int gradesSum;
- bool gradesSumBool = 0;
- };
- int gradesSumCounter = 0;
- int main()
- {
- int k; // Брой на студентите
- printf("Enter the number of students: ");
- scanf ("%d",&k);
- student* stud;
- stud = new(nothrow) student[k];
- // Инициализиране на динамичен масив stud от структурата student
- k++;
- for(int i =1; i< k; i++)
- {
- printf("Enter the student's name (index %d): \n", i);
- scanf("%30s", stud[i].name);
- printf("Enter the student's reference number (index %d): \n", i);
- scanf("%30s", stud[i].referenceNum);
- printf("Enter the student's grades: \n", i);
- for(int j =1; j<=5; j++)
- {
- printf("Enter grade number %d : \n", j);
- scanf("%d", stud[i].grades+j);
- }
- }
- for(int i =1; i<=k; i++)
- {
- int gradesSum = 0;
- for(int j =1; j<5; j++)
- {
- gradesSum += stud[i].grades[j];
- }
- stud[i].gradesSum = gradesSum;
- if(stud[i].gradesSum < 12)
- {
- stud[i].gradesSumBool =1;
- gradesSumCounter++;
- }
- }
- printf("---------------------\n");
- printf("The students with grades sum under 12: \n");
- for(int i =1; i<=gradesSumCounter; i++)
- {
- if(stud[i].gradesSumBool)
- {
- printf("%s ", stud[i].referenceNum);
- printf("%s ",stud[i].name);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement