Transformation

Published on February 2017 | Categories: Documents | Downloads: 53 | Comments: 0 | Views: 346
of 5
Download PDF   Embed   Report

Comments

Content

/* transformation */

#include <stdio.h>

/* include header file*/

#include <stdlib.h>
#define SIZE 16

void input(int *);
void transform(int *);
void inverse(int *);

int main()
{
int num[SIZE];
char y_n;
do{
printf("Please input the notes(input -1 to end the loop)\n ");
input(num);
transform(num);
inverse(num);
printf("\n Do you want to continue ? (y/n): ");
to continue */
scanf(" %c",&y_n);
}while(y_n!='n');
system("PAUSE");
return 0;
}
void input(int *num)
{

/* input the notes*/

/*ask if the user want

int i;
char note,sign;
for(i=0;i<SIZE;i++){

printf("%d:",i+1);
scanf(" %c%c",&note,&sign);
printf(" ");

/* separate the notes */

switch(note)
{
case 'C':

/*teat which note it is */

if(sign=='+')
{ num[i]=1;}
else

num[i]=0;

break;
case 'D':
if(sign=='+')
{ num[i]=3;}
else if ( sign=='-')
num[i]=1;
else num[i]=2;
break;
case 'E':
if(sign=='-')
{ num[i]=3;}
else

num[i]=4;

break;
case 'F':

if(sign=='+')
{ num[i]=6;}
else

num[i]=5;

break;
case 'G':
if(sign=='+')
{ num[i]=8;}
else if ( sign=='-')
num[i]=6;
else num[i]=7;
break;
case 'A':
if(sign=='+')
{ num[i]=10;}
else if ( sign=='-')
num[i]=8;
else num[i]=9;
break;
case 'B':
if(sign=='-')
{ num[i]=10;}
else

num[i]=11;

break;
}
if(note=='-'&&sign=='1')
{ num[i]=-1;
break;
}

}

/*end the input*/

}

void transform(int *num)

/* tramsform the num array into another array*

/
{
int i,factor,temp;
printf("Please input a factor: ");
scanf("%d",&factor);
for(i=0;i<SIZE;i++) {
if(num[i]==-1)

/* test if it is goint to the end*/

{ break;}
temp=factor - num[i];
if(temp<0)
{temp=temp+12;}
num[i]=temp;
}
}

void inverse(int *num)
{
int i;
printf("after transform: ");
for(i=0;i<SIZE;i++)
{
if(num[i]==0)
{printf("C ");}

/*inverse operation*/

if(num[i]==1)
{printf("C+/D- ");}
if(num[i]==2)
{printf("D ");}
if(num[i]==3)
{printf("D+/E- ");}
if(num[i]==4)
{printf("E ");}
if(num[i]==5)
{printf("F ");}
if(num[i]==6)
{printf("F+/G- ");}
if(num[i]==7)
{printf("G ");}
if(num[i]==8)
{printf("G+/A- ");}
if(num[i]==9)
{printf("A ");}
if(num[i]==10)
{printf("A+/B- ");}
if(num[i]==11)
{printf("B ");}
if(num[i]==-1)
{break;}
}
}

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close