q1
Why would a programmer use files instead of keyboard and monitor screen? List three C++ statements required to access data in disk file (think of libraries statement, required objects, required function calls, how to read/write).
q.2
What is the task of the recursive function below and how is it achieving the task you have identified?
int strange(int
n)
{
int result;
if (n == 1)
{
result = 0;
}
else
{
result = 1 + strange(n / 2);
}
return result;
}
With files we can use the large data efficiently.For people who can't enter the data for them it is useful.
The libraries we used are #include<fstream>
#include<fstream>
main()
{
std::fstream f;
f.open ("dmo.txt", std::fstream::in|std::fstream::out|std::fstream::app);
f << " some text";//write into file
getline(cin,line) //read line from file
f.close()
}
2)
The function takes the value and it adds the value 1 to the result until the number becomes 0
suppose if value is 9
result =1+result(9/2)=1+result(4)
result(4)=1+result(2)
result(2)=1+result(1)
result(9)=1+1+1+result(1)=1+1+1+0=3
It gives the value of how many times it takes to reach 0
q1 Why would a programmer use files instead of keyboard and monitor screen? List three C++...
In Unix/Linux, input and output are treated as files and referenced by the operating system using file descriptors. When you open a shell session, for example, three file descriptors are in use: 0 standard input (stdin) 1 standard output (stdout) 2 standard error (stderr) By default, the command interpreter (shell) reads keyboard input from file descriptor 0 (stdin) and writes output to file descriptor 1 (stdout), which appears on the screen. As you explored in Lab 2, input/output can be...
Fix this C++ below so does not use any loops at all. Use recursion instead. here is some guides given. Create a directory to hold assignment 3. Copy files hailstone.cpp, Makefile and dotestassignment 2 to the assignment 3 directory. Edit the comments at the top of hailstone.cppto say that this is assignment 3. You should be able to keep the same contracts, 'next' function and 'main' function from assignment 2, unless they contained errors that needed to be fixed. If...
C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...
GIVEN CODE- FILL IN THE
BLANK!
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
// Function ptototypes
int readX();
void writeX(int);
int main() /// chi read x ---> divi ---> write x into file
---> par read x --> sub--> write x into file---> chi
read x-->etc
{
int pid;
// pid: used to keep track of the child
process
int x = 19530; // x:
our value as integer
...
Using C++ in Visual Studios
Rewrite the code to use a Stack instead of a Queue. You will
need to think about the differences in the Stack and Queue. Think
about how they operate and how the nodes may differ.
Modify the code as necessary.
You will need to push to the Stack, pop from the Stack, peek at
the Stack. You will need a member functions like in the example
code. Your program will need to show that everything...
C Programming - Please Help us! Implementing Load Balancing, the 3 Base Code files are at the bottom: Implementing Load Balancing Summary: In this homework, you will be implementing the main muti-threaded logic for doing batch based server load balancing using mutexes Background In this assignment you will write a batch-based load balancer. Consider a server which handles data proces- sing based on user requests. In general, a server has only a fixed set of hardware resources that it can...
This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...
What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...
Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....
These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....