473,441 Members | 1,751 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,441 software developers and data experts.

Passing parameters and files

I'm creating 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.

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 == 1));
  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", "a");
  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.  
My doubt is what the error in these specific parts:

cadastro(&arq, escolar);

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

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

I would also like to know if the code is following what is required

If you don't understand what was requested, just tell me if the parameters are being passed and the file is being created correctly, if not, how to change it


Thanks
Nov 25 '22 #1
0 7411

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

Similar topics

2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
1
by: Maria | last post by:
Hello! I am new to Crystal reports an I have problems passing parameters form outside to Crystal report an creating a report with data from more than one table This is the problem: I have to...
2
by: Carlos | last post by:
Hi all, I am familiar with passing parameters to a thread function using C++, but I needt to learn it using C#. Can someone shed some light on how to do this? Code snippets will be great to show...
2
by: Akira | last post by:
Hello. I'm having problem with passing parameters from .aspx file to user control. Could anyone tell me how to pass parameters from .aspx file to user control(.ascx) and how to recieve parameters...
0
by: Paul Allan | last post by:
I am new to ASP.net (intermediate ASP developer). I am developing a ASP.net web application and I am having some difficulty calling and passing parameters to a function that is declared in my...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
4
by: David Freeman | last post by:
Hi There! I'm just wondering if there's a way to pass parameters (as if you were passing parameters to a ASCX web control) when calling an ASPX page? e.g. MyDetailsPage.UserName = "david" ...
2
by: Nab | last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised that you only need to pass the input parameter. The output parameter's value will be returned without the need to pass it...
1
by: Gert Wurzer | last post by:
Hi! I have an asp.net 2.0 web application that uses an iframe to access another asp.bet 2.0 webapp via https. I've already found a working prototype solution to create a dynamic iframe taking...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.