473,405 Members | 2,210 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,405 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.  
  3. #include <string.h> 
  4.  
  5.  
  6.  
  7. #define TAM 4 
  8.  
  9. typedef struct { 
  10.  
  11.   char nomeAluno[40], maeNome[40], nomePai[60]; 
  12.  
  13.   float media; 
  14.  
  15.   float nota1, nota2, nota3; 
  16.  
  17.   int dia, mes, ano,id; 
  18.  
  19.   double cpf; 
  20.  
  21. } cadastro_aluno; 
  22.  
  23.  
  24.  
  25. void cadastro(FILE *, cadastro_aluno *); 
  26.  
  27. void consulta(FILE *, cadastro_aluno *); 
  28.  
  29. void relatorio(FILE *, cadastro_aluno *); 
  30.  
  31. int main() { 
  32.  
  33.   FILE arq; 
  34.  
  35.   cadastro_aluno escolar[TAM]; 
  36.  
  37.   cadastro(&arq, escolar); 
  38.  
  39.   consulta(&arq, escolar); 
  40.  
  41.   relatorio(&arq, escolar); 
  42.  
  43.  
  44. void cadastro(FILE *arq1, cadastro_aluno *escolar1) { 
  45.  
  46.   int i = 0; 
  47.  
  48.   int op; 
  49.  
  50.   arq1 = fopen("teste", "a"); 
  51.  
  52.   if (arq1 == NULL) 
  53.  
  54.     printf("Erro ao criar o arquivo!\n"); 
  55.  
  56.   else { 
  57.  
  58.     do { 
  59.  
  60.       escolar1[i].id=i+1; 
  61.  
  62.       fprintf(arq1, "%i ",escolar1[i].id); 
  63.  
  64.  
  65.  
  66.       printf("\nNome aluno: "); 
  67.  
  68.       fflush(stdin); 
  69.  
  70.       scanf("%s", &escolar1[i].nomeAluno[40]); 
  71.  
  72.       fprintf(arq1, "%s ",escolar1[i].nomeAluno); 
  73.  
  74.  
  75.  
  76.       printf("\nNome da mae: "); 
  77.  
  78.       fflush(stdin); 
  79.  
  80.       scanf("%s", &escolar1[i].maeNome[40]); 
  81.  
  82.       fprintf(arq1, "%s ",escolar1[i].maeNome); 
  83.  
  84.  
  85.  
  86.       printf("\nNome do pai: "); 
  87.  
  88.       fflush(stdin); 
  89.  
  90.       scanf("%s", &escolar1[i].nomePai[40]); 
  91.  
  92.       fprintf(arq1, "%s ",escolar1[i].nomePai); 
  93.  
  94.  
  95.  
  96.       printf("\nDigite o cpf do aluno: "); 
  97.  
  98.       fflush(stdin); 
  99.  
  100.       scanf("%lf", &escolar1[i].cpf); 
  101.  
  102.       fprintf(arq1, "%lf ", escolar1[i].cpf); 
  103.  
  104.  
  105.  
  106.       printf("\nInforme o Ano que o aluno nasceu: "); 
  107.  
  108.       fflush(stdin); 
  109.  
  110.       scanf("%d", &escolar1[i].ano); 
  111.  
  112.       fprintf(arq1, "%d ", escolar1[i].ano); 
  113.  
  114.  
  115.  
  116.  
  117.  
  118.       printf("\nInforme o Dia escolar do aluno: "); 
  119.  
  120.       fflush(stdin); 
  121.  
  122.       scanf("%d", &escolar1[i].dia); 
  123.  
  124.       fprintf(arq1, "%d ", escolar1[i].dia); 
  125.  
  126.  
  127.  
  128.       printf("\nInforme o Mes escolar do aluno: "); 
  129.  
  130.       fflush(stdin); 
  131.  
  132.       scanf("%d", &escolar1[i].mes); 
  133.  
  134.       fprintf(arq1, "%d ", escolar1[i].mes); 
  135.  
  136.  
  137.  
  138.       printf("Informa a nota 1 do aluno: "); 
  139.  
  140.       fflush(stdin); 
  141.  
  142.       scanf("%f", &escolar1[i].nota1); 
  143.  
  144.       fprintf(arq1, "%f ", escolar1[i].nota1); 
  145.  
  146.  
  147.  
  148.       printf("Informa a nota 2 do aluno: "); 
  149.  
  150.       fflush(stdin); 
  151.  
  152.       scanf("%f", &escolar1[i].nota2); 
  153.  
  154.       fprintf(arq1, "%f ", escolar1[i].nota2); 
  155.  
  156.  
  157.  
  158.       printf("Informa a nota 3 do aluno: "); 
  159.  
  160.       fflush(stdin); 
  161.  
  162.       scanf("%f", &escolar1[i].nota3); 
  163.  
  164.       fprintf(arq1, "%f ", escolar1[i].nota3); 
  165.  
  166.  
  167.  
  168.       escolar1[i].media = 
  169.  
  170.           ((escolar1[i].nota1 + escolar1[i].nota2 + escolar1[i].nota3) / 3); 
  171.  
  172.       fprintf(arq1, "%f ", escolar1[i].media); 
  173.  
  174.  
  175.  
  176.       printf("\nDeseja cadastrar mais aluno? Digite 0 "); 
  177.  
  178.       scanf("%d", &op); 
  179.  
  180.       i++; 
  181.  
  182.     }while ((op == 0) && (i != 0)); 
  183.  
  184.           fclose(arq1); 
  185.  
  186.  
  187.  
  188.   } 
  189.  
  190.  
  191. void consulta(FILE *arq3, cadastro_aluno *escolar3) { 
  192.  
  193.   int i = 0; 
  194.  
  195.   int op; 
  196.  
  197.  
  198.  
  199.     char nomeConsulta[40]; 
  200.  
  201.     char nomeMaeConsulta[40]; 
  202.  
  203.     char nomePaiConsulta[40]; 
  204.  
  205.     float consultaNota; 
  206.  
  207.  
  208.  
  209.     printf("\nDigite 1 para consultar o nome do aluno: \n 2 para consultar o " 
  210.  
  211.            "nome do pai " 
  212.  
  213.            "da mae:\n 3 para consultar nome da mae: \n e 4 para fazer seleção " 
  214.  
  215.            "por nota: \n" 
  216.  
  217.            "para consultar nota: "); 
  218.  
  219.     scanf("%d", &op); 
  220.  
  221.     if (op == 1){  
  222.  
  223.       printf("\nDigite o nome do aluno que deseja consultar: "); 
  224.  
  225.       scanf("%s", &nomeConsulta[40]); 
  226.  
  227.     } else if (op == 2) { 
  228.  
  229.       printf("\nDigite o nome do pai do aluno que deseja consultar: "); 
  230.  
  231.       scanf("%s ", &nomePaiConsulta[40]); 
  232.  
  233.     } else if (op == 3) { 
  234.  
  235.       printf("\nDigite o nome da mãe do aluno: "); 
  236.  
  237.       scanf("%s", &nomeMaeConsulta[40]); 
  238.  
  239.     } else if (op == 4) { 
  240.  
  241.       printf("\nDigite 4 para fazer pesquisa por nota: "); 
  242.  
  243.       scanf("%f", &consultaNota); 
  244.  
  245.     } 
  246.  
  247.     printf("\n\n\n------RESULTADO CONSULTA------\n\n\n"); 
  248.  
  249.     for (i = 0; i < TAM + 3; i++) { 
  250.  
  251.       arq3 = fopen("teste", "r"); 
  252.  
  253.   if (arq3 == NULL){ 
  254.  
  255.     printf("Erro ao criar o arquivo!\n"); 
  256.  
  257.       } 
  258.  
  259.   else { 
  260.  
  261.       escolar3[i].id=i+1; 
  262.  
  263.       if ((strcmp(&escolar3[i].nomeAluno[40], &nomeConsulta[40]) == 0) ||   
  264.  
  265.           (strcmp(&escolar3[i].nomePai[40], &nomePaiConsulta[40]) == 0) || 
  266.  
  267.           (strcmp(&escolar3[i].maeNome[40], &nomeMaeConsulta[40]) == 0)) { 
  268.  
  269.         fscanf(arq3, "%i ", &escolar3[i].id); 
  270.  
  271.         printf("\nId: %i", escolar3[i].id); 
  272.  
  273.  
  274.  
  275.         fscanf(arq3, "%s ", escolar3[i].nomeAluno); 
  276.  
  277.         printf("Aluno: %s\n", escolar3[i].nomeAluno); 
  278.  
  279.  
  280.  
  281.         fscanf(arq3, "%s ", escolar3[i].nomePai); 
  282.  
  283.         printf("pai: %s\n", escolar3[i].nomePai); 
  284.  
  285.  
  286.  
  287.         fscanf(arq3, "%s ", escolar3[i].maeNome); 
  288.  
  289.         printf("mae: %s\n", escolar3[i].maeNome); 
  290.  
  291.  
  292.  
  293.         fscanf(arq3, "%d ", &escolar3[i].ano); 
  294.  
  295.         printf("ano: %d\n", escolar3[i].ano); 
  296.  
  297.  
  298.  
  299.         fscanf(arq3, "%d ", &escolar3[i].dia);         
  300.  
  301.         printf("dia: %d\n", escolar3[i].dia); 
  302.  
  303.  
  304.  
  305.         fscanf(arq3, "%d ", &escolar3[i].mes); 
  306.  
  307.         printf("mes: %d\n", escolar3[i].mes); 
  308.  
  309.  
  310.  
  311.         fscanf(arq3, "%f ", &escolar3[i].nota1); 
  312.  
  313.         printf("nota1: %f\n", escolar3[i].nota1); 
  314.  
  315.  
  316.  
  317.         fscanf(arq3, "%f ", &escolar3[i].nota2); 
  318.  
  319.         printf("nota2: %f\n", escolar3[i].nota2); 
  320.  
  321.  
  322.  
  323.         fscanf(arq3, "%f ", &escolar3[i].nota3);         
  324.  
  325.         printf("nota3: %f\n", escolar3[i].nota3); 
  326.  
  327.  
  328.  
  329.         fscanf(arq3, "%f ", &escolar3[i].media); 
  330.  
  331.         printf("media: %f\n", escolar3[i].media); 
  332.  
  333.         printf("cpf: %lf\n", escolar3[i].cpf); 
  334.  
  335.         if (escolar3[i].media < 5) { 
  336.  
  337.           printf("\nALUNO REPROVADO, MEDIA MENOR QUE 5"); 
  338.  
  339.         } else 
  340.  
  341.           printf("\nALUNO APROVADO MEDIA MAIOR QUE 5"); 
  342.  
  343.  
  344.  
  345.       } else if ((escolar3[i].nota1 == consultaNota) || 
  346.  
  347.                  (escolar3[i].nota2 == consultaNota) || 
  348.  
  349.                  (escolar3[i].nota3 == consultaNota)) { 
  350.  
  351.         printf("Aluno: %s\n", escolar3[i].nomeAluno); 
  352.  
  353.         printf("\npai: %s\n", escolar3[2].nomePai); 
  354.  
  355.         printf("\nmae: %s\n", escolar3[i].maeNome); 
  356.  
  357.         printf("\nano: %d\n", escolar3[i].ano); 
  358.  
  359.         printf("\ndia: %d\n", escolar3[i].dia); 
  360.  
  361.         printf("\nmes: %d\n", escolar3[i].mes); 
  362.  
  363.         printf("nota1: %f\n", escolar3[i].nota1); 
  364.  
  365.         printf("nota2: %f\n", escolar3[i].nota2); 
  366.  
  367.         printf("nota3: %f\n", escolar3[i].nota3); 
  368.  
  369.         printf("\nmedia: %f\n", escolar3[i].media); 
  370.  
  371.         printf("\ncpf: %lf\n", escolar3[i].cpf); 
  372.  
  373.         if (escolar3[i].media < 5) { 
  374.  
  375.           printf("\nALUNO REPROVADO, MEDIA MENOR QUE 5"); 
  376.  
  377.         } else 
  378.  
  379.           printf("\nALUNO APROVADO MEDIA MAIOR QUE 5"); 
  380.  
  381.       } 
  382.  
  383.     } 
  384.  
  385.     fclose(arq3); 
  386.  
  387.   } 
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. void relatorio(FILE *arq2, cadastro_aluno *escolar2) { 
  395.  
  396.   int i = 0; 
  397.  
  398.   arq2 = fopen("teste", "r"); 
  399.  
  400.   if(arq2 == NULL) 
  401.  
  402.         printf("\nErro ao criar o arquivo!\n"); 
  403.  
  404.     else{ 
  405.  
  406.   printf("\n\n\n--------RELATORIO GERAL-------\n\n\n"); 
  407.  
  408.   while(!feof(arq2)) { 
  409.  
  410.     fscanf(arq2, "%i ", &escolar2[i].id); 
  411.  
  412.     printf("\nId: %i", escolar2[i].id); 
  413.  
  414.     printf("\n\n---------------------\n\n"); 
  415.  
  416.  
  417.  
  418.     fscanf(arq2, "%s ", escolar2[i].nomeAluno); 
  419.  
  420.     printf("Aluno: %s\n", escolar2[i].nomeAluno); 
  421.  
  422.  
  423.  
  424.     fscanf(arq2, "%s ", escolar2[i].nomePai); 
  425.  
  426.     printf("pai: %s\n", escolar2[i].nomePai); 
  427.  
  428.  
  429.  
  430.     fscanf(arq2, "%s ", escolar2[i].maeNome); 
  431.  
  432.     printf("mae: %s\n", escolar2[i].maeNome); 
  433.  
  434.  
  435.  
  436.     fscanf(arq2, "%d", &escolar2[i].ano); 
  437.  
  438.     printf("ano: %d\n", escolar2[i].ano); 
  439.  
  440.  
  441.  
  442.     fscanf(arq2, "%d ", &escolar2[i].dia); 
  443.  
  444.     printf("dia: %d\n", escolar2[i].dia); 
  445.  
  446.  
  447.  
  448.     fscanf(arq2, "%d ", &escolar2[i].mes); 
  449.  
  450.     printf("mes: %d\n", escolar2[i].mes); 
  451.  
  452.  
  453.  
  454.     fscanf(arq2, "%f ", &escolar2[i].nota1); 
  455.  
  456.     printf("nota1: %f\n", escolar2[i].nota1); 
  457.  
  458.  
  459.  
  460.     fscanf(arq2, "%f ", &escolar2[i].nota2); 
  461.  
  462.     printf("nota2: %f\n", escolar2[i].nota2); 
  463.  
  464.  
  465.  
  466.     fscanf(arq2, "%f ", &escolar2[i].nota3); 
  467.  
  468.     printf("nota3: %f\n", escolar2[i].nota3); 
  469.  
  470.  
  471.  
  472.     fscanf(arq2, "%f ", &escolar2[i].media); 
  473.  
  474.     printf("media: %f\n", escolar2[i].media); 
  475.  
  476.  
  477.  
  478.     fscanf(arq2,"f", &escolar2[i].cpf); 
  479.  
  480.     printf("\ncpf: %f\n", escolar2[i].cpf); 
  481.  
  482.  
  483.  
  484.     if (escolar2[i].media < 5) { 
  485.  
  486.         printf("\nALUNO REPROVADO, MEDIA MENOR QUE 5"); 
  487.  
  488.       } else 
  489.  
  490.         printf("\nALUNO APROVADO MEDIA MAIOR QUE 5"); 
  491.  
  492.     } 
  493.  
  494.         fclose(arq2); 
  495.  
  496.   } 
  497.  
  498.  
  499.  


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
0 8495

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.