473,626 Members | 3,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameters and files

3 New Member
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(&escolar 3[i].nomeAluno[40], &nomeConsult a[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 7431

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

Similar topics

2
17348
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 (update, append) should be activated in order to transfer data to other tables. I tried to avoid any coding in VB, as I am not a professional, but I have found a statement in an article, that, unlike select queries, form's Input Property can't be...
7
49569
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. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
1
3624
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 make a report( VS.NET, C#, Web Form) with 3 parts and with data from three tables: 1st part: all the field values form table1 coresponding to an Id (Id
2
2183
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 me. Thanks in advance, Carlos
2
46393
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 at .ascx? Thank you for your help!
0
1547
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 "codebehind" page. Function declaration: Sub MyFunction(ByVal sender As Object, ByVal e As System.EventArgs)
4
2986
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 pass it to the Db and retrieveing data from a stored procedure, but I can't get the hang of parameters. I have a method where I can get the parameters passed to the sp but it doesn't want to return any results. Here's a copy of my code:
4
7153
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" OR... the only way to do it is to use the QueryString or Session object?
2
2019
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 as was the case in the previous version of VB e.g. VB .Net 2003. Here's the procedure in the web service: Public Sub Convert2Dollar(ByVal euroAmount As Double, ByRef usDollarAmount As Double) Dim exchangeRate As Double exchangeRate = 10 / 6
1
3468
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 URL parameters with an asp.net 2.0 literal. My problem is, that i can't use the URL parameters due to security reasons. Are there any other possibilities for passing parameters to another asp.net 2.0 web application, so that the parameters cannot...
0
8262
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5571
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.