473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

parameter passing

I am building a student registration system for college


The implementation must contain:

(1.1) Creation of the constructed record type - with at least 5 variables, three of which have different primitive data types -, declaration of the vector variable of the constructed record type (with at least 3 indices), and registration function WITH PAIR PASSAGE METROS (reading data from the keyboard) using a vector of records (heterogeneous composite variable) - being mandatory the use of a repetition loop to load the vector -. The registration must be done in the registration vector and then stored in a file (text or binary).

(1.2) Function WITH PASSING OF PARAMETERS for querying data within the record vector, containing - at least - a conditional structure with three different conditions separated by two logical operators (as well as the guidelines of Work 1). The query must be made in the content previously recorded in the file (text or binary).

(1.3) Function WITH PASSAGE OF PARAMETERS to print a complete report of the data registered in the record array. Printing must be done from the content previously recorded in the file (text or binary).

(1.4) The array variable(s) of records and the file variable(s) MUST be declared LOCAL.

(1.5) Among the passages of parameters, MUST be included, at least, by REFERENCE. At least one of the functions must return.

my code below

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define TAM 4
  5. typedef struct {
  6.   char nomeAluno[40], maeNome[40], nomePai[60];
  7.   float media;
  8.   float nota1, nota2, nota3;
  9.   int dia, mes, ano,id;
  10.   double cpf;
  11. } cadastro_aluno;
  12.  
  13. void cadastro(FILE *, cadastro_aluno *);
  14. void consulta(FILE *, cadastro_aluno *);
  15. void relatorio(FILE *, cadastro_aluno *);
  16. int main() {
  17.   FILE arq;
  18.   cadastro_aluno escolar[TAM];
  19.   cadastro(&arq, escolar);
  20.   consulta(&arq, escolar);
  21.   relatorio(&arq, escolar);
  22. }
  23. void cadastro(FILE *arq1, cadastro_aluno *escolar1) {
  24.   int i = 0;
  25.   int op;
  26.   arq1 = fopen("teste", "a");
  27.   if (arq1 == NULL)
  28.     printf("Erro ao criar o arquivo!\n");
  29.   else {
  30.     do {
  31.       escolar1[i].id=i+1;
  32.       fprintf(arq1, "%i ",escolar1[i].id);
  33.  
  34.       printf("\nNome aluno: ");
  35.       fflush(stdin);
  36.       scanf("%s", &escolar1[i].nomeAluno[40]);
  37.       fprintf(arq1, "%s ",escolar1[i].nomeAluno);
  38.  
  39.       printf("\nNome da mae: ");
  40.       fflush(stdin);
  41.       scanf("%s", &escolar1[i].maeNome[40]);
  42.       fprintf(arq1, "%s ",escolar1[i].maeNome);
  43.  
  44.       printf("\nNome do pai: ");
  45.       fflush(stdin);
  46.       scanf("%s", &escolar1[i].nomePai[40]);
  47.       fprintf(arq1, "%s ",escolar1[i].nomePai);
  48.  
  49.       printf("\nDigite o cpf do aluno: ");
  50.       fflush(stdin);
  51.       scanf("%lf", &escolar1[i].cpf);
  52.       fprintf(arq1, "%lf ", escolar1[i].cpf);
  53.  
  54.       printf("\nInforme o Ano que o aluno nasceu: ");
  55.       fflush(stdin);
  56.       scanf("%d", &escolar1[i].ano);
  57.       fprintf(arq1, "%d ", escolar1[i].ano);
  58.  
  59.  
  60.       printf("\nInforme o Dia escolar do aluno: ");
  61.       fflush(stdin);
  62.       scanf("%d", &escolar1[i].dia);
  63.       fprintf(arq1, "%d ", escolar1[i].dia);
  64.  
  65.       printf("\nInforme o Mes escolar do aluno: ");
  66.       fflush(stdin);
  67.       scanf("%d", &escolar1[i].mes);
  68.       fprintf(arq1, "%d ", escolar1[i].mes);
  69.  
  70.       printf("Informa a nota 1 do aluno: ");
  71.       fflush(stdin);
  72.       scanf("%f", &escolar1[i].nota1);
  73.       fprintf(arq1, "%f ", escolar1[i].nota1);
  74.  
  75.       printf("Informa a nota 2 do aluno: ");
  76.       fflush(stdin);
  77.       scanf("%f", &escolar1[i].nota2);
  78.       fprintf(arq1, "%f ", escolar1[i].nota2);
  79.  
  80.       printf("Informa a nota 3 do aluno: ");
  81.       fflush(stdin);
  82.       scanf("%f", &escolar1[i].nota3);
  83.       fprintf(arq1, "%f ", escolar1[i].nota3);
  84.  
  85.       escolar1[i].media =
  86.           ((escolar1[i].nota1 + escolar1[i].nota2 + escolar1[i].nota3) / 3);
  87.       fprintf(arq1, "%f ", escolar1[i].media);
  88.  
  89.       printf("\nDeseja cadastrar mais aluno? Digite 0 ");
  90.       scanf("%d", &op);
  91.       i++;
  92.     }while ((op == 0) && (i != 0));
  93.           fclose(arq1);
  94.  
  95.   }
  96. }
  97. void consulta(FILE *arq3, cadastro_aluno *escolar3) {
  98.   int i = 0;
  99.   int op;
  100.  
  101.     char nomeConsulta[40];
  102.     char nomeMaeConsulta[40];
  103.     char nomePaiConsulta[40];
  104.     float consultaNota;
  105.  
  106.     printf("\nDigite 1 para consultar o nome do aluno: \n 2 para consultar o "
  107.            "nome do pai "
  108.            "da mae:\n 3 para consultar nome da mae: \n e 4 para fazer seleção "
  109.            "por nota: \n"
  110.            "para consultar nota: ");
  111.     scanf("%d", &op);
  112.     if (op == 1){ 
  113.       printf("\nDigite o nome do aluno que deseja consultar: ");
  114.       scanf("%s", &nomeConsulta[40]);
  115.     } else if (op == 2) {
  116.       printf("\nDigite o nome do pai do aluno que deseja consultar: ");
  117.       scanf("%s ", &nomePaiConsulta[40]);
  118.     } else if (op == 3) {
  119.       printf("\nDigite o nome da mãe do aluno: ");
  120.       scanf("%s", &nomeMaeConsulta[40]);
  121.     } else if (op == 4) {
  122.       printf("\nDigite 4 para fazer pesquisa por nota: ");
  123.       scanf("%f", &consultaNota);
  124.     }
  125.     printf("\n\n\n------RESULTADO CONSULTA------\n\n\n");
  126.     for (i = 0; i < TAM + 3; i++) {
  127.       arq3 = fopen("teste", "r");
  128.   if (arq3 == NULL){
  129.     printf("Erro ao criar o arquivo!\n");
  130.       }
  131.   else {
  132.       escolar3[i].id=i+1;
  133.       if ((strcmp(&escolar3[i].nomeAluno[40], &nomeConsulta[40]) == 0) ||  
  134.           (strcmp(&escolar3[i].nomePai[40], &nomePaiConsulta[40]) == 0) ||
  135.           (strcmp(&escolar3[i].maeNome[40], &nomeMaeConsulta[40]) == 0)) {
  136.         fscanf(arq3, "%i ", &escolar3[i].id);
  137.         printf("\nId: %i", escolar3[i].id);
  138.  
  139.         fscanf(arq3, "%s ", escolar3[i].nomeAluno);
  140.         printf("Aluno: %s\n", escolar3[i].nomeAluno);
  141.  
  142.         fscanf(arq3, "%s ", escolar3[i].nomePai);
  143.         printf("pai: %s\n", escolar3[i].nomePai);
  144.  
  145.         fscanf(arq3, "%s ", escolar3[i].maeNome);
  146.         printf("mae: %s\n", escolar3[i].maeNome);
  147.  
  148.         fscanf(arq3, "%d ", &escolar3[i].ano);
  149.         printf("ano: %d\n", escolar3[i].ano);
  150.  
  151.         fscanf(arq3, "%d ", &escolar3[i].dia);        
  152.         printf("dia: %d\n", escolar3[i].dia);
  153.  
  154.         fscanf(arq3, "%d ", &escolar3[i].mes);
  155.         printf("mes: %d\n", escolar3[i].mes);
  156.  
  157.         fscanf(arq3, "%f ", &escolar3[i].nota1);
  158.         printf("nota1: %f\n", escolar3[i].nota1);
  159.  
  160.         fscanf(arq3, "%f ", &escolar3[i].nota2);
  161.         printf("nota2: %f\n", escolar3[i].nota2);
  162.  
  163.         fscanf(arq3, "%f ", &escolar3[i].nota3);        
  164.         printf("nota3: %f\n", escolar3[i].nota3);
  165.  
  166.         fscanf(arq3, "%f ", &escolar3[i].media);
  167.         printf("media: %f\n", escolar3[i].media);
  168.         printf("cpf: %lf\n", escolar3[i].cpf);
  169.         if (escolar3[i].media < 5) {
  170.           printf("\nALUNO REPROVADO, MEDIA MENOR QUE 5");
  171.         } else
  172.           printf("\nALUNO APROVADO MEDIA MAIOR QUE 5");
  173.  
  174.       } else if ((escolar3[i].nota1 == consultaNota) ||
  175.                  (escolar3[i].nota2 == consultaNota) ||
  176.                  (escolar3[i].nota3 == consultaNota)) {
  177.         printf("Aluno: %s\n", escolar3[i].nomeAluno);
  178.         printf("\npai: %s\n", escolar3[2].nomePai);
  179.         printf("\nmae: %s\n", escolar3[i].maeNome);
  180.         printf("\nano: %d\n", escolar3[i].ano);
  181.         printf("\ndia: %d\n", escolar3[i].dia);
  182.         printf("\nmes: %d\n", escolar3[i].mes);
  183.         printf("nota1: %f\n", escolar3[i].nota1);
  184.         printf("nota2: %f\n", escolar3[i].nota2);
  185.         printf("nota3: %f\n", escolar3[i].nota3);
  186.         printf("\nmedia: %f\n", escolar3[i].media);
  187.         printf("\ncpf: %lf\n", escolar3[i].cpf);
  188.         if (escolar3[i].media < 5) {
  189.           printf("\nALUNO REPROVADO, MEDIA MENOR QUE 5");
  190.         } else
  191.           printf("\nALUNO APROVADO MEDIA MAIOR QUE 5");
  192.       }
  193.     }
  194.     fclose(arq3);
  195.   }
  196. }
  197.  
  198.  
  199. void relatorio(FILE *arq2, cadastro_aluno *escolar2) {
  200.   int i = 0;
  201.   arq2 = fopen("teste", "r");
  202.   if(arq2 == NULL)
  203.         printf("\nErro ao criar o arquivo!\n");
  204.     else{
  205.   printf("\n\n\n--------RELATORIO GERAL-------\n\n\n");
  206.   while(!feof(arq2)) {
  207.     fscanf(arq2, "%i ", &escolar2[i].id);
  208.     printf("\nId: %i", escolar2[i].id);
  209.     printf("\n\n---------------------\n\n");
  210.  
  211.     fscanf(arq2, "%s ", escolar2[i].nomeAluno);
  212.     printf("Aluno: %s\n", escolar2[i].nomeAluno);
  213.  
  214.     fscanf(arq2, "%s ", escolar2[i].nomePai);
  215.     printf("pai: %s\n", escolar2[i].nomePai);
  216.  
  217.     fscanf(arq2, "%s ", escolar2[i].maeNome);
  218.     printf("mae: %s\n", escolar2[i].maeNome);
  219.  
  220.     fscanf(arq2, "%d", &escolar2[i].ano);
  221.     printf("ano: %d\n", escolar2[i].ano);
  222.  
  223.     fscanf(arq2, "%d ", &escolar2[i].dia);
  224.     printf("dia: %d\n", escolar2[i].dia);
  225.  
  226.     fscanf(arq2, "%d ", &escolar2[i].mes);
  227.     printf("mes: %d\n", escolar2[i].mes);
  228.  
  229.     fscanf(arq2, "%f ", &escolar2[i].nota1);
  230.     printf("nota1: %f\n", escolar2[i].nota1);
  231.  
  232.     fscanf(arq2, "%f ", &escolar2[i].nota2);
  233.     printf("nota2: %f\n", escolar2[i].nota2);
  234.  
  235.     fscanf(arq2, "%f ", &escolar2[i].nota3);
  236.     printf("nota3: %f\n", escolar2[i].nota3);
  237.  
  238.     fscanf(arq2, "%f ", &escolar2[i].media);
  239.     printf("media: %f\n", escolar2[i].media);
  240.  
  241.     fscanf(arq2,"f", &escolar2[i].cpf);
  242.     printf("\ncpf: %f\n", escolar2[i].cpf);
  243.  
  244.     if (escolar2[i].media < 5) {
  245.         printf("\nALUNO REPROVADO, MEDIA MENOR QUE 5");
  246.       } else
  247.         printf("\nALUNO APROVADO MEDIA MAIOR QUE 5");
  248.     }
  249.         fclose(arq2);
  250.   }
  251. }
  252.  
I would like to know if my code follows what is being asked

I would like to know what is wrong in the parts below:

cadastro(&arq, escolar);

}while ((op == 0) && (i != 1));XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

arq3 = fopen("", "r");

strcmp(&escolar3[i].nomeAluno[40], &nomeConsulta[40]) == 0)

fscanf(arq2, "%s ", escolar2[i].nomeAluno);

If you don't understand, just tell me if the parameter is being passed and if the file was created correctly. If not how to resolve.
Nov 25 '22 #1
1 9711
Larisabrownb
1 Bit
Parameter passing involves passing input parameters into a module (a function in C and a function and procedure in Pascal) and receiving output parameters back from the module. For example a lovelanguagetest.org quadratic equation module requires three parameters to be passed to it, these would be a, b and c.There are a number of different ways a programming language can pass parameters: Pass-by-value. Pass-by-reference. Pass-by-value-result The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value.Value-result parameter passing was used in Fortran IV and in Ada. The idea is that, as for pass-by-value, the value (not the address) of the actual parameters ...
Nov 28 '22 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mat Andrews | last post by:
Hi, I'm comfused with this peice of code which I'm looking at. I can't figure out how it works (and it does appear too); ApplicationData appData = new ApplicationData(); ...
0
by: KK | last post by:
Hi MCPP gurus' I have a small problem in parameter passing.This is my situation namespace Abc { public __gc class ClassAbc { public: String* Hello(String* str) {
0
by: stevag | last post by:
I have stored a variable ABC in a ASP.NET page and I use xsltArglist.AddParam in order to add this variable as a parameter to the binded XSLT transformation. In the associated .xslt file I use...
0
by: Richard Buckshaw | last post by:
Mimick the older C/ pascal dll parameter passing convention? - VB Class Mod? Hello, I have been attempting to write a VB class that would expose its stuff to an older (ok, legacy application)...
3
by: Robert | last post by:
What is the best way to pass a parameter to an ObjectDataSource. I am able to add a new parameter to the SelectParameters, but I would like to just assign a value to an existing parmeter at...
3
by: amadain | last post by:
Help. I'm new to php. I wrote a function that did not seem to work so I checked whether the parameter I was passing to the function was actually being used. I found that it wasn't. When I run the...
1
by: vijay.gandhi | last post by:
Hello, I have created a function in C++/CLI which was exported as a .DLL to be used in VB .NET. I have been having some problems (I think it has to do with the right syntax) with parameter...
16
by: Theo R. | last post by:
Hi all, Does the C99 Standard explicitly mention the need for a stack for passing arguments or Is this platform specific? As an example, the ARM9 processor recommends Core Registers R0-R3 be...
13
by: frakie | last post by:
Hi 'body, I'm experiencing difficulties on parameter passing. I wrote a library in last months, and now it crashes few times in a month because of errors in parameter passing: using gdb on the...
1
by: tarunkhatri | last post by:
Hi, I want to pass the parameter of employee_id to a page. My code is working fine and passing parameter to page but the problem is rather then the current parameter. It passed the parameter which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.