C++ program, Micrsoft Visual Studio (codes) Create a library with the following
ID: 662678 • Letter: C
Question
C++ program, Micrsoft Visual Studio (codes)
Create a library with the following functions, each of which has a return type of int and inputs A and B that are also of type int:
- pos_order: returns the next value in the increasing sequence of numbers; for example, if A = 8 and B = 5, the the function returns 11
- neg_order: returns the next value in the decreasing sequence of numbers; for example, if A = 8 and B = 5, the the function returns 2
- whole_avg: returns the average of A and B if the average is a whole number, otherwise returns 0
Next, creat a program that makes use of your library. Ask the user to input two values, call each function in the library, and output each result.
Explanation / Answer
// mylib.h
#ifndef MYLIB_H
#define MYLIB_H
int pos_order(int, int);
int neg_order(int, int);
int whole_avg(int, int);
#endif
//calc.c
#include "mylib.h"
int pos_order(int A, int B)
{
return B+(B-A);
}
int neg_order(int A, int B)
{
return A-(B-A);
}
int whole_avg(int A, int B)
{
int avg=(A+B)/2
if (floor(avg) == avg){
return avg;
}
else{ return 0;}
}
// main.c
#include <stdio.h>
#include "mylib.h"
int main()
{
int A, B;
printf("Enter two squence numbers");
scanf("%d %d",&A,&B)
printf("%d",pos_order(A,B));
printf("%d",neg_order(A,B));
printf("%d",whole_avg(A,B));
return 0;
}
building library:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.