Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer Science 1 C Programming Assignment Assignment: While spending the summe

ID: 3565232 • Letter: C

Question

Computer Science 1 C Programming Assignment

Assignment:

While spending the summer as a surveyor's assistant, you decide to write a program that transforms compass headings in degrees (0 to 360) to compass bearings.

A compass bearing consists of three items: the direction you face (north or south), an angle between 0 and 90 degrees, and the direction you turn before walking (east or west).

For example, to get the bearing for a compass heading of 110.0 degrees, you would first face due south (180 degrees) and then turn 70.0 degrees east (180.0 - 70.0 = 110.0). Therefore, the bearing is South 70.0 degrees East.

Input Validation: Be sure to check the input for invalid compass headings.

You must use separate functions to:

In addition, you must use both an if and a switch statement somewhere in your program.

Hint: Use integers to represent the directions (North, South, East, West), then use a switch statement to print the appropriate word for each value. You can use #define constants for the different values.

An output example would be: South 70.0 degrees East

If it prints due east, west, north, south on a 90, 180, 270, 360 degree output, that is extra credit.

To anyone who is able to do this program for me, I'll ask another very simple question worth 300 or 750 points for you to answer (depending if the extra credit portion is in the code) and award you the bonus points as well.

Explanation / Answer

#define MAX_LINE_BUFFER 256
#define DENSITY 1.23

//functions declaration
void balloon();
void compass();
void drag();

float to_hour(float h,float m);
int round(float x);




void main()
{
//local variables
int choice,confirm;
char temp[MAX_LINE_BUFFER];
char str,test;

do{//post test loop to repeat program

system("cls");
printf("==================Main Menu================== ");
printf(" 1 Weather balloons ");
printf(" 2 Compass Heading ");
printf(" 3 Drag Force ");
printf(" 4 Quit ");
printf("============================================= ");
printf("Please insert your choice: ");
fgets (temp, MAX_LINE_BUFFER, stdin); //store user input to temp, max 256bytes
sscanf(temp,"%c",&test);//scan 1st char in user input

if(!isdigit(test))//if 1st char is not num, invalid input
choice=0;
else
sscanf(temp,"%d%c",&choice,&str);//scanf for first int and char from temp

if(!isspace(str))//if str is not whitespace, make choice invalid
choice=0;

flushall();//clear remaining input in stream i.e. char after str


switch(choice)
{
case 1 : balloon(); //call balloon function
break;
case 2 : compass(); //call compass function
break;
case 3 : drag(); //call drag function
break;
case 4 : printf("Ended! ");
system("pause");
break;
default: system("cls");
printf("You have entered an invalid choice..! ");
printf("Please enter you choice again. ");
system("pause");
break;
}
}while(choice!=4);//stop looping when choice==4

}




//======================================== start of module 1 ==================================
void balloon()
{
int error=0,maxhour,hour,minute,maxminute,confirm;
float starthour,startminute,total_increment_hour,endhour,endminute,totalendhour,ihour,iminute;
float totalstarthour,height,velocity,maxheight=0,time,t;

do{
do{
do{
do{
system("cls");
//get start time
printf("Enter start time (less than 48hours) ");
printf("Hour: ");//prompt for start hour
scanf("%f",&starthour);
flushall();
printf("Minute: ");//prompt for start minute
scanf("%f",&startminute);
flushall();
totalstarthour=to_hour(starthour,startminute); //call func to convert to hour only

if(starthour<0 || startminute<0 || totalstarthour>48)
{
printf("Invalid time input! ");
printf("Please try again from the beginning. ");
system("pause");
}
}while(totalstarthour>48 || starthour<0 || startminute<0);//start over if invalid input



//get end time
printf(" Enter end time (less than 48 hours) ");
printf("Hour: ");//prompt for end hour
scanf("%f",&endhour);
flushall();
printf("Minute: ");//prompt for end minute
scanf("%f",&endminute);
flushall();

totalendhour=to_hour(endhour,endminute); //call func to convert to hour only

if( endhour<0 || endminute<0 || totalendhour>48 || totalendhour<=totalstarthour)
{
printf("Invalid time input! ");
printf("Please try again from the beginning. ");
system("pause");
}

}while(totalendhour>48 || endhour<0 || endminute<0 || totalendhour<=totalstarthour);
//start over if invalid input


//get time increment
printf(" Enter each line increment: ");
printf("Hour: ");
scanf("%f",&ihour);
flushall();
printf("Minute: ");
scanf("%f",&iminute);
flushall();

total_increment_hour=to_hour(ihour,iminute);//convert to hour only

//check for increment value error
error=0;
if(ihour>(endhour-starthour) || ihour==(endhour-starthour) && iminute>(endminute-startminute))
{
printf("The increment must be less than the different of starting and ending time. ");
error=1;
}
else if(total_increment_hour<0)
{
printf("Invalid value! ");
error=1;
}
else if(total_increment_hour==0)
{
printf("The increment cannot be zero! ");
error=1;
}
if(error==1)
{
printf("Please try again. ");
system("pause");
}

}while(error==1);//start over if invalid input



//print table
printf("%c======================================================%c ",213,184);
printf("| Time | Altitude | Velocity | ");
printf("| | (meter) | (meter/hour) | ");
printf("|-----------------+----------------+-------------------| ");

do{
//convert hour to hour and minute
hour = floor(totalstarthour);
minute=round((totalstarthour-floor(totalstarthour))*60);
if(minute==60)
{
hour+=1;
minute=0;
}

t=totalstarthour;
height= (-.12*pow(t,4))+(12*pow(t,3))-(380*t*t)+(4100*t)+220;//calc altitute
velocity= (-0.48*pow(t,3))+(36*t*t)-(760*t)+4100;//calc velocity

//print content of table
printf("| %02d:%02d ", hour,minute);
printf("| %10.3f ", height);
printf("| %10.3f | ",velocity);

if(height>maxheight)//to find greatest altitute
{
maxheight=height;
maxhour=hour;
maxminute=minute;
}

totalstarthour+=total_increment_hour;

}while(totalstarthour<=totalendhour);

printf("%c======================================================%c ",212,190);

//printf peak altitute and coresponding time
printf(" The peak altitude is %.3fm, at %02d:%02d. ",maxheight,maxhour,maxminute);
maxheight=0;//reset maxheight for user to continue in second loop
system("pause");

//prompt to continue?
do{
printf("Continue ??? ");
printf("1 yes 2 no >");
scanf("%d",&confirm);
flushall();
printf("%d ",confirm);
}while(confirm!=1 && confirm!=2);

}while(confirm!=2);//check if to continue
}


float to_hour(float h,float m)//convert hour and minute to hour in floating point
{
h=h+m/60;
return h;
}

int round(float x)//round up minute to fix trucation error of floating number
{
if((x-(int)x)>=0.5)
x=(int)x+1;
return x;
}



//==================================== start of module 2 ===========================
void compass()
{
//local variables
int confirm;
float bearing,dir;
char NorS[6],EorW[5];
do{
do{
bearing=-1;//initialize bearing to invalid value
system("cls");
printf("Bearing: ");//ask user to enter bearing
scanf("%f",&bearing);
flushall();
if(bearing<0 || bearing>360)
{
printf("Invalid bearing! Please try again. ");
system("pause");
}
}while(bearing<0 || bearing>360);//to start over if invalid input

//calc direction based on bearing quadrant
if(bearing>0&&bearing<90)
dir=bearing;
else if(bearing>=90&&bearing<=180)
dir=180-bearing;
else if(bearing>180&&bearing<270)
dir=bearing-180;
else if(bearing>=270&&bearing<=360)
dir=360-bearing;
else if(bearing==0)
dir=0;


//ternary conditional operators to decide which direction to print
(bearing<=90||bearing>=270? strcpy(NorS,"North"):strcpy(NorS,"South"));
(bearing<180? strcpy(EorW,"East"):strcpy(EorW,"West"));
printf("Compass Bearing: %s %.1f degree %s ",NorS,dir,EorW);

//prompt to continue?
do{
printf("Continue ??? ");
printf("1 yes 2 no >");
scanf("%d",&confirm);
flushall();
}while(confirm!=1 && confirm!=2);//prompt again if invalid input

}while(confirm!=2);//check if to continue
}



//============================================= start of module 3 =========================================
void drag()
{
float A,Cd,F;
int v,confirm,error=0;

do{
do{
do{
A=-1;//initialize area to invalid value
Cd=-1;//initialize coefficient to invalid value
system("cls");
printf("Please enter the value of projected area(in m%c)>>> ",253);
scanf("%f",&A);//prompt for area
flushall();
if(A<0)//to check if area is valid
{
printf("Invalid area! ");
printf("Please try again from the beginning. ");
system("pause");
}
}while(A<0);//to start over if invalid input



printf("Please enter the value of drag coefficient>>> ");
scanf("%f",&Cd);
flushall();
if (Cd<0)//to check if drag coefficient is valid
{
printf("Invalid coefficient! ");
printf("Please try again from the beginning. ");
system("pause");
}
}while(Cd<0);//to start over if invalid input


//print table
printf("%c=================================%c ",213,184);
printf("| Velocity | Drag force | ");
printf("| (m/s) | (N) | ");
printf("|---------------+-----------------| ");


for(v=0;v<=40;v++)//do for every v in between 0 and 40
{
F=(float)1/2*Cd*A*DENSITY*v*v;//calculate drag force
printf("| %02d ",v);
printf("| %10.3f | ",F);
}

printf("%c=================================%c ",212,190);

//prompt to continue?
do{
printf("Continue ??? ");
printf("1 yes 2 no >");
scanf("%d",&confirm);
flushall();
}while(confirm!=1 && confirm!=2);//prompt again if invalid input

}while(confirm!=2);//check if to continue
}

Posted by ReeveMonk at 11:07 PM No comments:

2009 Communication systems assignment..

Question:
Universiti XXXXXXXX

Faculty of Engineering and Science


XXXXX Communication Systems
Assignment

In Lab 2, you are shown how to model a baseband binary NRZ coded communication system using Matlab. In this assignment you have to modify some of the functions given to you in Lab 2 in order to model a slightly different communication system. You are required to model a baseband binary communication system using Manchester coding, instead of NRZ coding. Again, sampling rate is 1000Hz and data rate is 100 bps.

i) The function nrz( ) has to be modified to produce the Manchester coded waveform. Use the short data string b = [1 0 0 1 1 1 0 1 0 1] and plot out the Manchester coded waveform. The Manchester coded waveform should range from -1V to +1V.
ii) Modify the low pass channel function lpchannel( ) so that it will have a bandwidth of 350 Hz. Send the signal through it and plot the output waveform.
iii) Modify the noise code so that it will produce added white Gaussian noise with single sided spectral density of N0 = 10mW/Hz. Add the noise generated to the signal and plot the resultant waveform
iv) Work out the voltage difference of the symbols s1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote