• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 11 páginas
Otro

The Body Mass Index Program and Matric Certificate Program, Compulsory assignments

Document preview thumbnail
Vista previa 2 fuera de 11 páginas

Assignments 2 and 3 in Mat1503 deal with vectors and determinants ,particularly helpful for engineering and computer science students who will apply these principles in real life through the design of efficient search engine algorithms (matrices and determinants ) and safer vehicles (vectors) The assignments 2 and 3 in COS1511 deal with solving common problems and automating simple tasks such as calculating your BMI (Body Mass Index) and automating a Matric Certificate program in a more interactive manner.

Vista previa del contenido

Shivam_12596388_Assignment 2_uniqueCode_830369



Question 1 COS1511 Assignment 2: Writing Function headers in C++

Part (i): The function that returns no value from the caller
void check(int param1,float param2)
{
param1>param2;
param2=param1;
param2<param1;

}




Part (ii): The function that multiplies two values and returns the result:
void mult(float var1,float var2)
{
cout<<var1*var2;
}
int main()
{
mult(2,3);

return 0;

}




Part (iii): The function that tells you how many seconds, minutes and hours are in a day
void time(int seconds, int minutes,int hours)
{
cout<<"Within a day there are
"<<seconds<<"seconds,”<<minutes<<”minutes”<<hours<<”hours in a day
“<<endl<<endl;
}
int main()
{
time (60,60,24,);
return 0;
}

, Shivam_12596388_Assignment 2_uniqueCode_830369



Part (iv): The function that counts the amount of characters in a given string (phrase or sentence)

void countChar (string phraseofCharacters,int TotalCharacters)
{

phraseofCharacters="MonkeyBanana";

TotalCharacters=12;

cout<<"The phrase "<<phraseofCharacters<< " has "
<<TotalCharacters<< "Characters in the phrase
"<<phraseofCharacters<<endl<<endl<<endl;

}
int main ()
{
countChar( "MonkeyBanana",12 );

return 0;
}




Question 2 COS1511 Assignment 2: Debugging Errors in functions

Correcting errors in output code 2i

To call a function, simply do the following;
int main()
{
function1();

return 0;
}

Do not do the following in terms of calling functions

a) endl; int function2()

b) cout << "Inside function function1 " << endl;

Do the following to correct the above errors when calling functions in C++

• Always include the function you created within the main function within the default int
main () function.

• Never include endl;when ending functions , simply use the {} to end functions

• You cannot call a function without stating it in int main()

Información del documento

Subido en
9 de noviembre de 2022
Número de páginas
11
Escrito en
2022/2023
Tipo
Otro
Personaje
Desconocido
$12.09

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
shivamnaik
5.0
(1)
Vendido
7
Seguidores
2
Artículos
15
Última venta
1 semana hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes