Exercise #1:
Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work.
Answer:-
#include <stdio.h>
/*int f1(int y);
int f2(int y);
void f3(int&x);*/
void f4(int x,int& addr1,int& addr2);
int main()
{
int x,num_of_tens,remainder;
/*Question a //Prompt for a number between 10-99 and loop until
correct*/
do {
printf("Enter a 2 digit number: ");
scanf("%d", &x);
} while (x < 10 || x>99);
/*Question b//Hard code x value a 2 digit number and display the
value divided by 10
x = 59;
printf("%d\n", (x / 10));*/
/*Question c//Hard code x value a 2 digit number and display
remainder while it divided by 10
x = 59;
printf("%d\n", (x % 10));*/
/*Question d//Find number of tens using function
x = 59;
printf("Value of x before function call = %d\n", x);
printf("Number of 10s in %d = %d\n", x,f1(x));
printf("Value of x after function call = %d\n", x);
//Question e/Find remainder using function
printf("Value of x before function call = %d\n", x);
printf("Remainder by dividing 10 of %d = %d\n", x, f2(x));
printf("Value of x after function call = %d\n", x);*/
x = 59;
/*question f
printf("Value of x before function call = %d\n", x);
printf("Value of x using function call = ");
f3(x);
printf("Value of x after function call = %d\n", x);*/
/*question g &h
printf("Value of x before function call = %d\n", x);
f3(x);
printf("Value of x after function call = %d\n", x);*/
//Call f4 to get number of tens and remainder
f4(x,num_of_tens,remainder);
printf("Value of x = %d\n", x);
printf("Number of 10s in %d = %d\n", x, num_of_tens);
printf("Remainder by dividing 10 of %d = %d\n", x,
remainder);
return 0;
}
/*
Function: f1
ParamIn: y, value of x from main
ParamOut: Value of 10's
Description: Function take value of x from main and return number
of 10's
*/
int f1(int y) {
return y / 10;
}
/*
Function: f2
ParamIn: y, value of x from main
ParamOut: Remainder while dividing by 10
Description: Function take value of x from main and return
remainder by dividing by 10
*/
int f2(int y) {
return y % 10;
}
/*
Function: f3
ParamIn: &x, Address of the integer x
ParamOut: None
Description: Function print the value of x address pointing
*/
/*void f3(int& x) {
printf("%d\n", *&x);
}*/
/*
Function: modified f3
ParamIn: &x, Address of the integer x
ParamOut: None
Description: add 4 with x address pointing integer
*/
/*void f3(int& x) {
*&x += 4;
}*/
/*
Function: f4
ParamIn: x, Integer
&addr1, address of num_of_tens
&addr2, address of remainder
ParamOut: None
Description: Calculate number of 10's and remainder and change the
corresponding address values
*/
void f4(int x, int& addr1, int& addr2) {
*&addr1 = x / 10;
*&addr2 = x % 10;
}
Exercise #1: Write a C program that contains the following steps (make sure all variables are...
Using C programming language
Question 1 a) through m)
Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....
Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...
Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...
Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variables to any legal value of your choosing. Next, declare and initialize a pointer variable to each of the variables Using printf), output the following: The address of each of the first three variables. Use the "Ox%x" format specifier to print the addresses in hexadecimal notation The value of each variable. They should equal the value you gave...
Write a C++ program that will count the number of words and vowels in a sentence. Create a bool function called isVowel that accepts a character as a parameter and returns a true if it’s a vowel (aeiou) and false otherwise. Create an int function named countVowels that will accept a string variable as a parameter and will return the number of vowels in it. Call the isVowel function as part of this process. Write an int function named countWords...
C++ CODE
/* This is program project 2 on page 695.
* Before you begin the project, please read the project description
* on page 695 first.
*
* Author: Your Name
* Version: Dates
*/
#include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
class Fraction
{
public:
// constructor
Fraction(int a, int b);
// generate a fraction which is a/b
Fraction(int a);
// generate a fraction which is a/1
Fraction();
// generate a fraction which is 0/1. i.e...
C++ CODE
/* This is program project 2 on page 695.
* Before you begin the project, please read the project description
* on page 695 first.
*
* Author: Your Name
* Version: Dates
*/
#include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
class Fraction
{
public:
// constructor
Fraction(int a, int b);
// generate a fraction which is a/b
Fraction(int a);
// generate a fraction which is a/1
Fraction();
// generate a fraction which is 0/1. i.e...
Salary Lab In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than 1 department, and at the end of the file...
Match the definition with the vocabulary word that best fits the definition. The library used for formatting output. The location of a variable in memory The library used to read and write to files Data that is passed back to the calling function as the function ends. When an argument is passed to a function this way, a copy of the argument (or of the value stored in the argument variable) is copied into a function parameter variable. A statement...
11p
Python Language
Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...