Thread: Help with a project

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    2

    Help with a project

    Hi there, i need a help with writing a program with 3 functions:
    void Init (char ***names, int **grades, int *size) that gets The function initializes through input from the user a set of names and a set of scores. Both arrays of the same size, size. Whenever data is collected for arrays, they must be valid. If the user typed an invalid statistic, an error message should be printed and an alternate statistic requested. A valid score is complete between 0 and 100. A valid name meets the following conditions:• Begins with a large Latin letter.
    • All but the first characters are lowercase Latin characters.
    • Not already in the array. (The array must not contain the same name twice.)
    For example:
    Enter number of students: 3
    Enter name: Ronit
    Enter grade: 79
    Enter name: yosi
    Bad name. Try again: YOSI
    Bad name. Try again: Y051
    Bad name. Try again: Yosi
    Enter grade: 93
    Enter name: Ronit
    Bad name. Try again: Efrat
    Enter grade: 888
    Bad grade. Try again: 88

    the second function is int Find (char **names, int *grades, int size, char *name) The function accepts, as parameters, an array of names, an array of scores, and the size of these arrays. In addition, it receives as a student name parameter. The function finds the student's position in the set of names, and returns its grade. If the student does not appear in the set, 1- will be returned.
    For example, if the arrays names, grades are like the previous example, size = 3, name = ”Efrat”, then the returned value is 88.

    the last function is void FreeAll (char ***names, int **grades, int size) The function neatly frees all the memory of the arrays.

    THANKS A LOT

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What sort of help do you need?

    Is it everything, or just the finer detail of dealing with three stars and malloc?

    Can you for example complete the assignment if you started with
    char names[10][100];
    int grades[10];


    What does your proposed main() look like?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2020
    Posts
    2
    Hi mate
    the main supposed to use with the help of functions we have created an array that receives a number of student receives it, prints the result and eventually releases all memory.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So in a very basic sense, you could do this.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void input( char ***ptr ) {
      *ptr = malloc( sizeof(**ptr) );
      (*ptr)[0] = malloc( 20 * sizeof(***ptr) );
      strcpy((*ptr)[0],"King Arthur");
    }
    
    int main ( ) {
      char **ptr;
      input( &ptr );
      printf("Result=%s\n", ptr[0] );
      free( ptr[0] );
      free( ptr );
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    505
    You've got two conditions on the name. Firstly that it be a valid Latin name, secondly that it not be already entered. I would handle these rather different requirements separately.

    Start by writing a function that tests if the name is a valid Latin name. Then write another function that tests whether a name is in a list of strings - a list of strings is passed
    in as a char ** together with a size variable. Get the first function working, then the second. Then populate your name list from input, and check for duplicates, and put in the
    error suppression code. Then you substantially have your init function.

    To test it, write another function, called something like "dump_results". This will print out your list of names with associated grades. You don't submit this function, it
    is just there to test that init() has been written corectly and is doing what you want it to do.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. Replies: 5
    Last Post: 02-23-2013, 03:37 PM
  3. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 01:48 AM
  4. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM

Tags for this Thread