0% found this document useful (0 votes)
7 views5 pages

Structure Array

Structure c++ program

Uploaded by

ahmedilyas5440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Structure Array

Structure c++ program

Uploaded by

ahmedilyas5440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <iostream>

#include <string>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct items{

string name;

float price;

int quantity;

};

class Product{

private:

items item[10];

int n=0;

public:

void insert(){

if(n>=10){

cout<<"Array is full."<<endl;

else{

cout<<"Enter item name"<<endl;

cin>>item[n].name;

cout<<"Enter item price"<<endl;

cin>>item[n].price;

cout<<"Enter item quantity"<<endl;

cin>>item[n].quantity;

n++;

void display(){
if(n>=10){

cout<<"Array is empty."<<endl;

else{

for(int a=0;a<n;a++){

cout<<a+1<<endl;

cout<<"Item name"<<endl;

cout<<item[a].name<<endl;

cout<<"Item Price"<<endl;

cout<<item[a].price<<endl;

cout<<"Item Quantity"<<endl;

cout<<item[a].quantity<<endl;

void Delete(){

int ind;

string num;

cout<<"Enter the item name to delete: ";

cin>>num;

for(int a=0;a<n;a++){

if(item[a].name==num){

ind=a;

break;

for(int b=ind;b<n;b++){

item[b]=item[b+1];
}

n--;

void update(){

string old,New;

cout<<"Enter old item name."<<endl;

cin>>old;

cout<<"Enter new item name."<<endl;

cin>>New;

for(int a=0;a<n;a++){

if(item[a].name==old){

item[a].name=New;

break;

void search(){

string sea;

cout<<"Enter item name."<<endl;

cin>>sea;

for(int a=0;a<n;a++){

if(item[a].name==sea){

cout<<"Item is at index "<<a<<" and item is


exit."<<endl;

break;

}
};

int main(int argc, char** argv) {

Product p1;

int ch;

while(true){

cout<<"Menu"<<endl;

cout<<"1. insert"<<endl;

cout<<"2. display"<<endl;

cout<<"3. Delete"<<endl;

cout<<"4. Search"<<endl;

cout<<"5. update"<<endl;

cout<<"6. exit"<<endl;

cin>>ch;

switch(ch){

case 1:

p1.insert();

break;

case 2:

p1.display();

break;

case 3:

p1.Delete();

break;

case 4:

p1.search();

break;

case 5:

p1.update();

break;
case 6:

return 0;

break;

default:

cout<<"Invalide input."<<endl;

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy