Facebook
From Thendo Tshikota, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 237
  1. //Develop a program that would calculate the sum of the arithmetic sequence Tn = 400 + (n-1)
  2. //Write a program that allows a user to search an array for a name, if the name exists the program should print the name, if it doest exist it should ask whether the user would like to add the name or not, if the user agrees , the user should be able to add the name (5).
  3. //Write an OOP program that prints the length of your name (5)
  4. //Discuss the difference between imperative and functional c++
  5. //Create a C++ Function that returns the Largest and the smallest number given an array
  6. //Create a function that returns true if a number is odd
  7. //Discuss the types of pointers in c++
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12. #define ARRAY_SIZE 4
  13. #define ARRAY_EXTENDED_SIZE 5
  14.  
  15. int main()
  16. {
  17. int choice;
  18. bool found = false;
  19. string names[ARRAY_SIZE] = {"john","ndivho","budzwa","edmond"};
  20. string namesextended[ARRAY_EXTENDED_SIZE];
  21. string name;
  22.  
  23. cout << "Welcome to the student names database , type in a name to see if it exsists. : ";
  24. cin >> name;
  25.  
  26.  
  27.  
  28.  
  29. for(int i=0;i<ARRAY_SIZE;i++)
  30. {
  31.  
  32. if(names[i]==name)
  33. {
  34. cout << names[i] << " exsists at " << i;
  35. found = true;
  36. break;
  37. }
  38. }
  39.  
  40. if(found!=true)
  41. {
  42. cout << "The name doesnt exsist , would you like to add it? 1.Yes 2.No : " ;
  43. cin >> choice;
  44.  if(choice==1)
  45.  {
  46.  string str;
  47.         cout<< "Enter the name you would like to add : ";
  48.         cin >> str;
  49.  
  50.  for(int i = 0;i<ARRAY_SIZE;i++)
  51.  {
  52.         namesextended[i]=names[i];
  53.  }
  54.  namesextended[ARRAY_SIZE] = str;
  55.  cout << str <<" has been added to the list of names";
  56.  cout << endl;
  57.  }
  58. }
  59.  
  60.  
  61.  if(choice==1)
  62.  {
  63.  for(int i=0;i<ARRAY_EXTENDED_SIZE;i++)
  64.  {
  65.     cout << namesextended[i]<<endl;
  66.  }
  67. }
  68.  
  69. }
  70.  

Replies to search rss

Title Name Language When
Re: search Crimison Owl cpp 3 Years ago.
Re: vhulenda Crimson Owl cpp 3 Years ago.