Question

In: Computer Science

Write a C/C++ program to maintain a fixed size library of 1024 documents, whose size randomly...

Write a C/C++ program to maintain a fixed size library of 1024 documents, whose size randomly ranges between 2MB to 3MB.

Solutions

Expert Solution

#include <iostream>

using namespace std;
// struct to maintin the document details
struct document{
int id;
string name;
string description;
};
int main()
{
//array with size of 1024 as it is fixed
document docList[1024];
int index=0,ch;
int id;
string n,d;
bool flag=true;
// loop to ask details until they want to exit
while(flag){
cout<<"1 Add Document\n2 Search Document\n3 Exit\n";
cin>>ch;
switch(ch){
//reading document details
case 1:{
cout<<"Enter document ID,Name,Description: ";
cin>>id;
cin>>n;
cin>>d;
document dd={id,n,d};
//adding to list
docList[index++]=dd;
break;
}
//searching the document by taking iD
case 2:{
cout<<"Enter document Id: ";
cin>>id;
int found=0;
for(int i=0;i<index;i++){
if(id==docList[i].id){
found=1;
cout<<"Id : "<<docList[i].id<<endl;
cout<<"Name : "<<docList[i].name<<endl;
cout<<"Description : "<<docList[i].description<<endl;
  
}
}
if(!flag){
cout<<"Document does not exist with given ID\n";
}
break;
}
case 3:flag=false;
}
  
  
}
cout<<"Bye..!!!";

return 0;
}


Related Solutions

Write a C++ program to maintain a fixed size library of 1024 documents, whose size randomly...
Write a C++ program to maintain a fixed size library of 1024 documents, whose size randomly ranges between 2MB to 3MB.
Many documents use a specific format for a person's name. Write a program whose input is:...
Many documents use a specific format for a person's name. Write a program whose input is: firstName middleName lastName and whose output is: lastName, firstInitial.middleInitial. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: user_input = input() splits = user_input.split(" ") if(len(splits) == 3): first_name = splits[0] middle_name = splits[1] last_name = splits[2] print(last_name + ", " + first_name[0] + "." + middle_name[0] + ".") elif(len(splits) == 2): first_name = splits[0]...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
In objective-C Task: Write a program whose input is a character and a string, and whose...
In objective-C Task: Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is:...
Programming Language Required: C Write a multithreaded program in C (not c++) using the pthread library...
Programming Language Required: C Write a multithreaded program in C (not c++) using the pthread library and dynamic memory(malloc) that multiplies two matrices together. The numbers in the matrices must be read in from a text file. The program should also check if the two matrices are capable of being multiplied together. The amount of threads used has to be dynamic. The user should be able to choose how many threads they wish to use using the command line. Finally,...
Write a C program whose input is two integers, and whose output is the first integer...
Write a C program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a...
Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on...
Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on the command line. For example: prompt$: ./vowcon Operating Systems Class at CSUN The main() in this program should read the phrase from the terminal. This phrase can be read into a global variable. This phrase or its parts can be directly accessed from the main() and from the threads. The main() has to create two threads running functions (vow and con). The main() can...
Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
1. Create a Word document in the Documents library. Write a small “summary or review” of...
1. Create a Word document in the Documents library. Write a small “summary or review” of an interesting “technology article” – The topics can be anything related to recent news in technology “Example: Launching of new gadgets of Apple, or Artificial Intelligence and its uses, Amazon Web Services etc” please include workcited
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT