Thread: Basic C

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Basic C

    Hey, so basically coming towards the end of the first term at university, i've been set an assignment worth 40% of the years marks. Unfortunately the lecturer has been ill for the past few weeks, and i'm kinda stumped. I'm not going to ask for much help, but getting some advice and helping me understand a little would be a great help.

    Here is a cut version of the assignment: assignment.docx

    Thanks.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Nobody here, in their right mind is going to open a doc or docx file over the internet.

    Plus we don't do people's homework for them...

    If you get into a problem with the code, post it here and we'll see what we can do.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    The assignment:

    Objective: To develop a C Program to calculate components of matching
    attenuators.

    Introduction: You are to develop a C program to help design resistive attenuation and matching
    pads for a telephone line. Generally, telephone lines and electronic equipment need to be matched to
    their source and loads to avoid reflection of the signals. Attenuators are used to reduce the level of
    large signals that need to be fed to a more sensitive circuit.

    Theory:
    The two types of attenuator are Tee and Pi. Both are used extensively.
    There are two types of each, balanced and unbalanced. Unbalanced type use a
    Common earthed return, while balanced types do not.
    The Tee arrangement can be used in its unbalanced form, or its balanced form

    (Sometimes known as a balanced H network).

    Figure 1: Tee Networks with equations.













    Figure 2: Pi Network with equations.



    Figure 3: Minimum Loss Pad.


    Z1 is the impedance seen looking into the network, while Z2 is the impedance seen
    looking into the output. So if the source (generator) has an output impedance of 600
    And the load has an impedance of 75then the network will be arranged to have
    Z1=600, and Z2=75.
    Since the networks are all designed to introduce a loss (expressed in dB or Decibels)
    then this is used, with the Z1, Z2 values to calculate the resistor values.

    Task:

    What you have to do is develop a program to ask the user what kind of
    network she/he wants, what the input and output impedance's are to be, and what the loss is. The program should then calculate the value of the resistance values and display them, along with the other network parameters. You might like to start by designing the program for the Tee network first. Then go on to develop the Pi network. Test each as you develop it to avoid having a lot of error to deal with at one time. Finally, the program askes the user if they want to save the design to a file. This involves saving the resistor values, input and output impedances, and attenuator loss information to a file. Hint: Use a C struct for this so as to keep all the data together. You will need to do some research to complete this part of the assignment.

    The complete program can be developed as a menu program with an option to terminate the program, or perform another calculation.

    Test Case example:
    Test Case 1: If Z1=600 ohms, Z2=900 ohms, an unbalanced Tee with a loss of 15db would have the following resistor values. R1=369.29 ohms, R2=688.89 ohms,
    R3=269.88 ohms.
    For other test cases, check your results by comparing with hand calculations.

  4. #4
    C Newbie
    Join Date
    Oct 2011
    Posts
    59
    In order for anyone to help, you have to have some work done. Do as much as you can, and when stumped on a specific spot, ask for help.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    Yeah sorry I was in the library.

    Basically I can do the remotely easy stuff, such as the menus. I'm having trouble with implicating the equations themselfs, and implimenting them into the code.

    So far for my Tee network I have;

    Code:
    /* Attenuator Calculator Program */
    #include<stdio.h>
    #include<math.h>
    
    float Tee(void); /*Tee Network*/
    float Pi(void); /*Pi Network*/
    float Minimum_Loss(void); /* Minimum Loss*/
    float Balanced(void);
    float Unbalanced(void);
    
    
    
     main(void)    {
    char choice;
    
    printf("-----Welcome to the Attenuator calculator program----");
    do{
    printf("\n\n");
    printf("Enter \n T=Tee Network \n P=Pi Network \n I=Minimum Loss \n Z=Quit\n");
    
    choice=getchar();
    switch(toupper(choice)) {
    case 'T': Tee();break;
    case 'P': Pi();break;
    case 'I': Minimum_Loss();break;
    case 'Z': printf("\nThank you for using the Attenuator calculator program!\n");break;
    default: printf("\nThere is no option for this letter; please try again\n"); break;
    }
    }while(choice != 'Z'&& choice != 'z');
    }
    
    /* End of Menu */
    
    
    /*-------------------- For Tee Network ---------------*/    
        
        float Tee(void){
        
    
        
        char choice;    
    
    printf("\n\nIs the network balanced or unbalanced?");                         
    
    do{
     printf("\n\n");
     printf("Enter: \n B=Balanced Network \n U=Unbalanced Network\n Z=Quit");
     fflush(stdin);
     
     choice=getchar();
       switch(toupper(choice))  {
         case 'B': Balanced();break;
         case 'U': Unbalanced();break;
         case 'Z': printf("Thank you for using the attenuator calculator program!");break;
         default: printf("There is no option for this letter, please try another letter");
         }
        }while(choice != 'Z'&& choice !='z');
        }
        
        
        
        float Balanced(){
        
        printf("Enter value for input impedance");
    }
    
        float Unbalanced(){
        
        printf("Enter Value for input Impedance");
        
        }
    Any help from here? Thanks.
    Last edited by toddeeeEEee; 12-05-2011 at 12:10 AM.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well, for starts, your compiler should be complaining like crazy...
    Referring to the code sample in message 5...

    Line 7 ... you prototype a function that does not exist in your code.
    Line 13 ... it's int main (void) ... and it returns an integer to the OS at the closing brace.
    Line 23 to 27 ... you should not stack stuff up on a line like that, it's too easy to miss something.
    Code:
    switch(toupper(choice)) 
       {
         case 'T': 
            Tee();
            break;
         case 'P': 
            Pi();
            break;
         case 'I': 
            Minimum_Loss();
            break;
         case 'Z': 
            printf("\nThank you for using the Attenuator calculator program!\n");
            return 0;
         default: 
            printf("\nThere is no option for this letter; please try again\n");
       }
    Line 30 ... you are exiting main without returning an integer value; usually 0.
    Line 37 ... you declare tee() to return a float but you never do return a float.
    Line 48 ... fflush(stdin); is a non-standard use of fflush() and in many compilers can result in erratic behaviour. Don't use it.
    Lines 51 to 56 ... see above...
    Lines 62 and 67 ... you declare functions to return floats but never do return a value

    As general commentary...
    Your source code formatting needs serious work... and yes it does matter. Bad formatting makes code harder to read.

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    To be fair, this is my first attempt at a program besides the obvious 'Hello world' tutorial. I'm using Quincy 2005, and everything seems to be coming out without errors :/ ( Forgot to mention it has to be done through Quincy, if that makes a difference or not ). Sorry if I sound stupid here.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by toddeeeEEee View Post
    To be fair, this is my first attempt at a program besides the obvious 'Hello world' tutorial. I'm using Quincy 2005, and everything seems to be coming out without errors :/ ( Forgot to mention it has to be done through Quincy, if that makes a difference or not ). Sorry if I sound stupid here.
    Ok then... you've done pretty good for your first program...
    But you did ask...

    I would suggest you get some solid learning materials, a book or a decent tutorial and study them... read every word, compile all the examples and do all the quizzes... page by page... You'll learn a lot more a lot faster than by trial and error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with some basic C++
    By 3321thec in forum C++ Programming
    Replies: 6
    Last Post: 09-06-2007, 08:15 PM
  2. new to C. need basic help
    By k4k45hi in forum C Programming
    Replies: 84
    Last Post: 09-04-2007, 04:39 AM
  3. need some help with basic C++
    By ramonnie in forum C++ Programming
    Replies: 6
    Last Post: 06-28-2007, 11:15 AM
  4. vc++ basic help
    By gooddevil in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2004, 11:01 AM
  5. VB vs. BASIC
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 07-05-2002, 08:55 PM