Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

CCPS 393 exam questions and answers guaranteed pass

Beoordeling
-
Verkocht
-
Pagina's
16
Cijfer
A+
Geüpload op
20-03-2026
Geschreven in
2025/2026

C - correct answers C Explain the difference between %d and %4d placeholders when printing - correct answers %4d reserves 4 spaces and right aligns the text, e.g 4285 6 but %d would just be centered write the commands to read a string from input and print it out. Assume a macro is define with max size SZ - correct answers char s[SZ]; printf("Enter a string with max size %d: ", SZ); fgets(s, SZ, stdin); s[strlen(s) - 1] = '0'; printf("You entered: %s n", s); Write the "cookbook" steps to reading/writing from a file - correct answers declare file pointers: FILE* in; FILE* out; initialize pointers: in=fopen("filename", "r"); out=fopen("filename", "w"); actions: fscanf(in, "placeholder", &variable); fprintf(out, "placeholder", variable); close files: fclose(in); fclose(out); write the general syntax for a switch statement - correct answers switch (variable) { case (cond1): action1; break; case (cond2): case (cond3): action2; break; } fill in the blanks: void swap (int *a, int *b) { int temp; temp=____; // set to variable pointed to by a ____ = ____; // set variable pointed to by a to the one pointed to by b ____ = temp; // set the variable pointed to by b } int main() { int a=5, b=7; swap( ____, ____); // a is now 7, b is now 5 return 0; } - correct answers *a *a = *b *b swap(&a, &b) write out the general format for a makefile - correct answers targetfile : dependenciesfiles action (gcc ...) targetfile2 : dependeciesfiles2 action ... and so on the executable show_face depends on object files show_face.o and face.o show_face.o depends on the source file show_face.c face.o depends on the source file face.c write the makefile - correct answers show_face : show_face.o face.o gcc show_face.o face.o -o show_face show_face.o : show_face.c gcc -c show_face.c face.o : face.c gcc -c face.c clean: rm *.o suppose you have a source file powers.c which contains the following functions: int square (int n) {...} int cube (int n) {...} int quartic (int n) {...} write the header file powers.h for these functions - correct answers int square(int); int cube(int); int quartic(int); Adding on to the previous question, you now have powers.h and powers.c. Assume your main function is in the file power_table.c, which calls the functions from powers.c. What will you include at the top other than what is usually included? write out the makefile to compile an executable power_table which depends on power_table.o and powers.o (include -lm for math). What does power_table.o depend on? What about powers.o? Include the clean command - correct answers #include "powers.h" power_table : power_table.o powers.o gcc power_table.o power.o -lm -o power_table power_table.o : power_table.c powers.h gcc -c power_table.c powers.o : powers.c powers.h gcc -c powers.c clean: rm *.o write the general structure of a for loop to read from a file. Assume the file pointer is already initiated and the file is open - correct answers for (condition) { fscanf(file_ptr, "placeholder", &storagevariable); // other actions } assume you are reading an unknown amount of lines from a file. write the general structure of a while loop to do so. Assume the file pointer and all necessary variables are initiated. - correct answers status=fscanf(file_ptr, "placeholder", &storagevariable); while (status != EOF) { // action status=fscanf(file_ptr, "placeholder", &storagevariable); } write a while loop to check if EOF is reached while reading line by line from a file - correct answers fscanf(file_ptr, "placeholder", &storagevariable) while (!(feof (file_ptr)) { fscanf(file_ptr, "placeholder", &storagevariable) } 5 'rules' for arrays: 1) size must be specified... 2) size ____ be changed 3) uninitialized arrays contain ____ 4) ____ bulk assignments 5) name of the array without [] is its ____ - correct answers at decleration cannot garbage no starting address write the general structure of a loop to iterate over an array. Assume size is predefined as SZ - correct answers for (int i=0; iSZ; i++) { arr[i]=whatever; // OR something=arr[i]; } declare an array of chars that contains the name "Amy". Be mindful of the amount of characters - correct answers char name[4] = "Amy"; include a 4th for the null character How do you use strcpy? - correct answers copy a string to another strcpy(destination, source); How do you use strncpy? - correct answers copy part of a string to another strncpy(destination, source, size_to_copy); write the declaration for the main where you will be accepting and keeping track of command line arguments. How would you verify that at least 1 command line argument was provided? What function would you use to convert the first command line argument to an integer? - correct answers int main(int argc, char* argv[]) { int n; if (argc 2) { // verify at least 1 command line arg .... n=atoi(argv[1]); } } What's the general structure for a struct in C? - correct answers typedef struct { type var1; type var2; typ2 var3; ... } struct_name; OR struct struct_name { type var1; type var2; ... }; How do you access a structs parameter? For example, how would you print the name of a variable planet which is of type planets_t? - correct answers bute printf("%s", ); How would you create a new planets_t object named planet1 with name Earth, diameter 1000, 1 moon, orbit 1.0 and rotation 24.0 in that order? - correct answers planets_t planet1={"Earth", 1000, 1, 1.0, 24.0}; suppose variable solarsystem is of type solar_systems_t and one of its attributes is an array of planets (type planets_t) called the_planets. How would you access the 3rd planet in that array? - correct answers planets_t newplanet = _planets[2]; how do you access the variable of a structure when using a pointer? For example, assume pointer pp points to a cartesian coordinate and you want to get the value of y - correct answers pointer-attribute printf("%d", pp-y); How would you keep reading from stdin until you've read all the inputs, with a maximum number of inputs MAXSIZE? Assume all floating point numbers and keep track of the size - correct answers double array[MAXSIZE]; int size=0, i; while (sizeMAXSIZE && scanf("%lf", &array[size]) != EOF) { size++; } C++ - correct answers C++ When you plan on using vectors, what should you include in your program? - correct answers #include vector How do you declare a vector? - correct answers vectordataType vectorName(numElements); How do you access elements at certain positions of a vector? For example, print out the 2nd element of a vector items - correct answers cout (1); How would you iterate over a vector? - correct answers for (int i=0; i(); i++) { // actions } How do you change the size of a vector? - correct answers e(newSize); how do you add an element to the back of a vector? - correct answers _back(newElement); what does () do? - correct answers returns the last element in the vector without altering anything what does _back() do? - correct answers removes the last element of the vector. It returns nothing How would you access an element in an array vs a vector? - correct answers myArr[i] vs myV(i) suppose the following: int arrayList[5]; vectorint vectorList(5); does arrayList[6] cause an error? does vectorL(6) cause an error? - correct answers No, and it wouldn't either for vectors i.e vectorList[6] yes What's the general structure for a function? - correct answers returnType funcName (argumentType argument) { // actions return whatever; } write a function declaration StrFunc which takes in a C string as argument called modString. Assume the function returns nothing - correct answers void StrFunc(char modString[]) { // actions } True or False + explain: Passing a C string to a function creates a copy of that string within the function - correct answers False. A pointer to the string is automatically passed, hence the original string is modified When does the scope of a variable within a function start and end? - correct answers after its declaration until its end What's the general structure for a class? - correct answers class ClassName { public: // insert public members and functions private: // insert private members and functions }; What's the general structure for a function within a class? - correct answers returnType ClassName::FuncName(args) { // actions } Can a non-const member function call a const member function? - correct answers No, it must also be const What's the general structure for a default constructor? - correct answers ClassName::ClassName() { var1="default1"; var2=0; // or whatever default is }; How would you overload the constructor? - correct answers Create a constructor of the same name but with different arguments How would you define an operator overload? use + as an example - correct answers ClassName ClassName::operator+(ClassName RHS) { ClassName total; // define new obj bute1=attribute1 + RHS.attribute1; bute2=attribute2 + RHS.attribute2; ... return total; } How would you define a pointer to an object of a class? How would you access its attribute? How would you call its member function? - correct answers ClassName* varPointer = new ClassName(var1, var2...); varPointer-attribute; varPointer-func(); Explain what deleting a pointer does i.e delete varPointer; Can we dereference i.e *varPointer after deletion? - correct answers It deallocates the memory block that varPointer points to (but does not make it null). If varPointer=nullptr, there is no effect. No, it will cause errors What's the general structure for a destructor? - correct answers ClassName::~ClassName() { // actions } Write a destructor for a linked list class called FrogsList which is made up of FrogNode objects - correct answers FrogsList::~FrogsList() { while (head) { FrogNode* next = head-next; delete head; head = next; } What's the general structure for a copy constructor when the data object is a pointer? What's the general structure for a copy constructor when the data object is not a pointer? - correct answers ClassName::ClassName(const ClassName& origObject) { dataobject = new type; *dataobject=*(origObject); } ClassName::ClassName(const ClassName& origObject) { dataobject=origObject; } When an object with an int sub-object is passed by value to a function, is there an error? How about with an int* sub-object? - correct answers no error - local copy is destructed only error - causes crash since destructor is called twice Consider the number n 12.34. What would cout fixed n print it out as? - correct answers 12.340000 When you use setprecision() and fixed togethe

Meer zien Lees minder
Instelling
CCPS
Vak
CCPS

Voorbeeld van de inhoud

CCPS 393 exam questions and
answers guaranteed pass

C - correct answers C



Explain the difference between %d and %4d placeholders when printing - correct answers %4d reserves
4 spaces and right aligns the text, e.g

4285

6



but %d would just be centered



write the commands to read a string from input and print it out. Assume a macro is define with max size
SZ - correct answers char s[SZ];

printf("Enter a string with max size %d: ", SZ);

fgets(s, SZ, stdin);

s[strlen(s) - 1] = '\0';

printf("You entered: %s \n", s);



Write the "cookbook" steps to reading/writing from a file - correct answers declare file pointers:

FILE* in;

FILE* out;



initialize pointers:

in=fopen("filename", "r");

out=fopen("filename", "w");



actions:

,fscanf(in, "placeholder", &variable);

fprintf(out, "placeholder", variable);



close files:

fclose(in);

fclose(out);



write the general syntax for a switch statement - correct answers switch (variable) {

case (cond1):

action1;

break;



case (cond2):

case (cond3):

action2;

break;

}



fill in the blanks:



void swap (int *a, int *b) {

int temp;

temp=____; // set to variable pointed to by a

____ = ____; // set variable pointed to by a to the one pointed to by b

____ = temp; // set the variable pointed to by b

}



int main() {

int a=5, b=7;

, swap( ____, ____); // a is now 7, b is now 5

return 0;

} - correct answers *a

*a = *b

*b



swap(&a, &b)



write out the general format for a makefile - correct answers targetfile : dependenciesfiles

action (gcc ...)

targetfile2 : dependeciesfiles2

action

... and so on



the executable show_face depends on object files show_face.o and face.o



show_face.o depends on the source file show_face.c



face.o depends on the source file face.c



write the makefile - correct answers show_face : show_face.o face.o

gcc show_face.o face.o -o show_face

show_face.o : show_face.c

gcc -c show_face.c

face.o : face.c

gcc -c face.c

clean:

rm *.o

Geschreven voor

Instelling
CCPS
Vak
CCPS

Documentinformatie

Geüpload op
20 maart 2026
Aantal pagina's
16
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

€14,16
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF


Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
RealGrades Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
189
Lid sinds
2 jaar
Aantal volgers
52
Documenten
12115
Laatst verkocht
1 week geleden

4,0

26 beoordelingen

5
12
4
5
3
7
2
1
1
1

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen