Quiz-Nov
.pdf
keyboard_arrow_up
School
Humber College *
*We aren’t endorsed by this school
Course
IPC144
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
10
Uploaded by DeaconStarGerbil23
1-
What will be the output of the following code? // C Program to illustrate the strcat function #include <stdio.h> int
main() { char
dest[50] = "This is an"
; char
src[50] = " example"
; printf
(
"dest Before: %s\n"
, dest); // concatenating src at the end of dest strcat
(dest, src); printf
(
"dest After: %s"
, dest); return
0; }
2-
What will be the output of the following code? / C program to demonstrate the strlen() function #include <stdio.h> #include <string.h> int
main() { // Declare and initialize a character array 'str' with // the string "GeeksforGeeks" char
str[] = "GeeksforGeeks"
; // Calculate the length of the string using the strlen() // function and store it in the variable 'length' size_t
length = strlen
(str); // Print the length of the string printf
(
"String: %s\n"
, str); printf
(
"Length: %zu\n"
, length); return
0; }
3-
What will be the output of the following code? int
main() { // Define a string 'str1' and initialize it with "Geeks" char
str1[] = "Geeks"
; // Define a string 'str2' and initialize it with "For" char
str2[] = "For"
; // Define a string 'str3' and initialize it with "Geeks" char
str3[] = "Geeks"
; // Compare 'str1' and 'str2' using strcmp() function and // store the result in 'result1' int
result1 = strcmp
(str1, str2); // Compare 'str2' and 'str3' using strcmp() function and // store the result in 'result2' int
result2 = strcmp
(str2, str3); // Compare 'str1' and 'str1' using strcmp() function and // store the result in 'result3' int
result3 = strcmp
(str1, str1);
// Print the result of the comparison between 'str1' and // 'str2' printf
(
"Comparison of str1 and str2: %d\n"
, result1); // Print the result of the comparison between 'str2' and // 'str3' printf
(
"Comparison of str2 and str3: %d\n"
, result2); // Print the result of the comparison between 'str1' and // 'str1' printf
(
"Comparison of str1 and str1: %d\n"
, result3); return
0; }
4-
What will be the output of the following code? // C program to illustrate the use of strcpy() #include <stdio.h> #include <string.h> int
main() { // defining strings char
source[] = "GeeksforGeeks"
; char
dest[20]; // Copying the source string to dest strcpy
(dest, source); // printing result printf
(
"Source: %s\n"
, source); printf
(
"Destination: %s\n"
, dest); return
0; }
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
#include
using namespace std;
void myfunction(int num2, int num1);
lint main() {
my function (5,2);
return 0; }
void myfunction(int num1, int num2)
{if (num1>3)
cout << "A1";
else if (num1<3)
cout<<"A2";
else
cout<<"A3";}
O A2
O A1
O A3
A1 A2 A3
arrow_forward
Q. You are asked to write a C program by storing student’s roll no., name along with their marks of six subjects for which you created a structure of ‘n’ students asfollows:struct student{int rollno;char name[25];int sub-marks[6];}s[n];
Do the followings on the above structure.i) Display all the student details by passing the structure to a function.ii) Find the total mark obtained by each student in all the six subjects.iii) Find the total in each subject obtained by all the students.iv) Print the details of the student who got the highest and who got the lowest marks assuming that there is one student who got the highest mark and one student who got the lowest mark.
arrow_forward
This is the C code I have so far
#include <stdio.h>
#include <stdlib.h>
struct employees
{
char name[20];
int ssn[9];
int yearBorn, salary;
};
// function to read the employee data from the user
void readEmployee(struct employees *emp)
{
printf("Enter name: ");
gets(emp->name);
printf("Enter ssn: ");
for (int i = 0; i < 9; i++)
scanf("%d", &emp->ssn[i]);
printf("Enter birth year: ");
scanf("%d", &emp->yearBorn);
printf("Enter salary: ");
scanf("%d", &emp->salary);
}
// function to create a pointer of employee type
struct employees *createEmployee()
{
// creating the pointer
struct employees *emp = malloc(sizeof(struct employees));
// function to read the data
readEmployee(emp);
// returning the data
return emp;
}
// function to print the employee data to console
void display(struct employees *e)
{
printf("%s", e->name);
printf(" %d%d%d-%d%d-%d%d%d%d",…
arrow_forward
C++ Functions provide a means to modularize applications
Write a function called "Calculate"
takes two double arguments
returns a double result
For example, the following is a function that takes a single "double" argument and returns a "double" result
double squareArea(double side){ double lArea; lArea = side * side; return lArea;}
arrow_forward
C++ program
Write a function named "reduce" that takes two positive integer arguments (as reference), call them "num" and "denom", treats them as the numerator and denominator of a fraction, and reduces the fraction.The function should return the value 0 (to indicate failure to reduce: if either of the two arguments is zero) and should return the value 1 otherwise.Function Prototype: bool reduce(int & num,int & denom);
arrow_forward
C++ Language
arrow_forward
C++
Plz solve as you can quickly
arrow_forward
Assume the Product structure is declared in c++ as follows:struct Product{string description; // Product descriptionint partNum; // Part numberdouble cost; // Product cost};
Now write a loop that will step through the entire array array of 100 Product structures (do not initialize the array), setting all the product descriptions to an empty string, all part numbers to zero, and all costs to zero.
( Drop the screenshot of output as well )
arrow_forward
C PROGRAMMING: FUNCTION
arrow_forward
5. A function can return a value of an enumeration type.
True
False
arrow_forward
Question #1
Study the following C program and answer the below questions
Hint: you might run it in Dev C++ before starting answering the questions!
#include
int main(void) {
int number;
char choice;
printf("Please enter an integer number: " ) ;
scanf("%d" , &number);
printf("\nTo check whether the number is even or odd, press e \n");
printf("To check whether the number is positive or negative, press p \n");
printf("To check whether the number is multiple of 10, press m \n");
printf("\nPlease enter your choice: ");
scanf(" %c" , &choice);
switch(choice) {
case 'e':
case 'E':
if (number % 2 == 0){
printf("\n%d is even \n" , number);
else {
printf("\n%d is odd \n" , number);
}
break;
case 'p':
case 'P':
if (number > 0){
printf("\n%d is positive \n" , number);
else if (number < 0){
printf("\n%d is negative \n" , number);
else {
printf("\n%d is zero! \n" , number);
break;
case 'm':
case 'M':
if (number % 10 == 0){
printf("\n%d is a multiple of 10
' , number);
}
else {
printf("\n%d is NOT a…
arrow_forward
C++
arrow_forward
Question #1
Study the following C program and answer the below questions
Hint: you might run it in Dev C++ before starting answering the questions!
#include
int main(void){
int number;
char choice;
printf("Please enter an integer number: ");
scanf("%d" , &number);
printf"\nTo check whether the number is even or odd, press e \n");
printf"To check whether the number is positive or negative, press p n"):
printf("To check whether the number is multiple of 10, press m \n");
printf("\nPlease enter your choice: "):
scanf(" %c" , &choice);
switch(choice) {
case 'e':
case 'E':
if (number % 2 -- 0){
printf"n%d is even \n", number);
else {
printf"\n%d is odd \n", number);
break;
case 'p':
case 'P':
if (number > 0){
printf"\n%d is positive \n", number):
else if (number <0){
printf("n%d is negative \n" , number);
else {
printf"n%d is zero! n", number);
break;
case 'm':
case 'M':
if (number % 10 -- 0){
printf"\n%d is a multiple of 10 \n" , number);
else {
printf("n%d is NOT a multiple of 10 n" ,…
arrow_forward
C++ Programming
arrow_forward
C++, functions and arrays (please don't use hard or high level code)
arrow_forward
C++ Code: DNA Sequence
The main() function is already written for you. You will implement the function int numOccurrences(string& STR, string& sequence). Without even understanding what functions do in C++, all you need to know, at this point, is that you have access to the string STR of which you have to find the length of the largest consecutive occurrence in the string sequence.
For example,
if input sequence is:
AGACGGGTTACCATGACTATCTATCTATCTATCTATCTATCTATCTATCACGTACGTACGTATCGAGATAGATAGATAGATAGATCCTCGACTTCGATCGCAATGAATGCCAATAGACAAAA
then
numOccurrences("AGAT", sequence) should return 5
numOccurrences("TATC", sequence) should return 8
if input sequence is:
AACCCTGCGCGCGCGCGATCTATCTATCTATCTATCCAGCATTAGCTAGCATCAAGATAGATAGATGAATTTCGAAATGAATGAATGAATGAATGAATGAATG
then
numOccurrences("AATG", sequence) should return 7
numOccurrences("TATC", sequence) should return 4
if input sequence is:…
arrow_forward
pointers as Arguments:In the C programming language there is no pass-by-reference syntax to passa variable by reference to a function. Instead a variable is passed by pointer(just to be confusing, sometimes passing by pointer is referred to as pass byreference). This Practice Program asks you to do the same thing as C.Here is the header for a function that takes as input a pointer to an integer:1. void addOne (int ∗ptrNum )Complete the function so it adds one to the integer referenced by ptrNum.Write a main function where an integer variable is defined, give it an initialvalue, call addOne, and output the variable. It should be incremented by 1.
arrow_forward
language = python
arrow_forward
[c++]
struct patient_data{
string name;
string no_id_card;
int hand_set_number;
string address;
};
figure 1
By referring to the struct definition in Figure A, you are required to do a STRUCT declaration of MPI clinic patients and write a complete program in C++ in order to input data and display the output for 50 patients of MPI clinic
arrow_forward
write code c++
creat struct names student
Suppose the students' names 1. Lara 2. Rashed 3. sara
Suppose any degrees u want
#declare in the struct
matrix[3][3]
#definition three function
one function Receive the quiz mark in the first column
the second function receive the mid mark in the second column
the third function receive the final mark in third column
# print the marks by using main function
arrow_forward
c code
Screenshot and output is must
arrow_forward
Use C++ don't change the main function just complete the deleteRepeats function
arrow_forward
C++ Programming
Lecture 6
Example 1: Write a C++ program to read student's mark and print "passed" if it
is greater than 50.
#include
#include
void main ()
{
int mark;
cout > mark;
if (mark > 50)
cout
#include
void main ()
{
int n, d;
cout > n >> d;
if(n%d !-0)
cout<
arrow_forward
C++ Tutorial so use C++ for code
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Related Questions
- #include using namespace std; void myfunction(int num2, int num1); lint main() { my function (5,2); return 0; } void myfunction(int num1, int num2) {if (num1>3) cout << "A1"; else if (num1<3) cout<<"A2"; else cout<<"A3";} O A2 O A1 O A3 A1 A2 A3arrow_forwardQ. You are asked to write a C program by storing student’s roll no., name along with their marks of six subjects for which you created a structure of ‘n’ students asfollows:struct student{int rollno;char name[25];int sub-marks[6];}s[n]; Do the followings on the above structure.i) Display all the student details by passing the structure to a function.ii) Find the total mark obtained by each student in all the six subjects.iii) Find the total in each subject obtained by all the students.iv) Print the details of the student who got the highest and who got the lowest marks assuming that there is one student who got the highest mark and one student who got the lowest mark.arrow_forwardThis is the C code I have so far #include <stdio.h> #include <stdlib.h> struct employees { char name[20]; int ssn[9]; int yearBorn, salary; }; // function to read the employee data from the user void readEmployee(struct employees *emp) { printf("Enter name: "); gets(emp->name); printf("Enter ssn: "); for (int i = 0; i < 9; i++) scanf("%d", &emp->ssn[i]); printf("Enter birth year: "); scanf("%d", &emp->yearBorn); printf("Enter salary: "); scanf("%d", &emp->salary); } // function to create a pointer of employee type struct employees *createEmployee() { // creating the pointer struct employees *emp = malloc(sizeof(struct employees)); // function to read the data readEmployee(emp); // returning the data return emp; } // function to print the employee data to console void display(struct employees *e) { printf("%s", e->name); printf(" %d%d%d-%d%d-%d%d%d%d",…arrow_forward
- C++ Functions provide a means to modularize applications Write a function called "Calculate" takes two double arguments returns a double result For example, the following is a function that takes a single "double" argument and returns a "double" result double squareArea(double side){ double lArea; lArea = side * side; return lArea;}arrow_forwardC++ program Write a function named "reduce" that takes two positive integer arguments (as reference), call them "num" and "denom", treats them as the numerator and denominator of a fraction, and reduces the fraction.The function should return the value 0 (to indicate failure to reduce: if either of the two arguments is zero) and should return the value 1 otherwise.Function Prototype: bool reduce(int & num,int & denom);arrow_forwardC++ Languagearrow_forward
- C++ Plz solve as you can quicklyarrow_forwardAssume the Product structure is declared in c++ as follows:struct Product{string description; // Product descriptionint partNum; // Part numberdouble cost; // Product cost}; Now write a loop that will step through the entire array array of 100 Product structures (do not initialize the array), setting all the product descriptions to an empty string, all part numbers to zero, and all costs to zero. ( Drop the screenshot of output as well )arrow_forwardC PROGRAMMING: FUNCTIONarrow_forward
- 5. A function can return a value of an enumeration type. True Falsearrow_forwardQuestion #1 Study the following C program and answer the below questions Hint: you might run it in Dev C++ before starting answering the questions! #include int main(void) { int number; char choice; printf("Please enter an integer number: " ) ; scanf("%d" , &number); printf("\nTo check whether the number is even or odd, press e \n"); printf("To check whether the number is positive or negative, press p \n"); printf("To check whether the number is multiple of 10, press m \n"); printf("\nPlease enter your choice: "); scanf(" %c" , &choice); switch(choice) { case 'e': case 'E': if (number % 2 == 0){ printf("\n%d is even \n" , number); else { printf("\n%d is odd \n" , number); } break; case 'p': case 'P': if (number > 0){ printf("\n%d is positive \n" , number); else if (number < 0){ printf("\n%d is negative \n" , number); else { printf("\n%d is zero! \n" , number); break; case 'm': case 'M': if (number % 10 == 0){ printf("\n%d is a multiple of 10 ' , number); } else { printf("\n%d is NOT a…arrow_forwardC++arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning